首页 > 解决方案 > GetMapping 在 Spring Boot 中返回错误 405

问题描述

我有一个在服务器端使用 Spring Boot 的系统。我收到一个错误,我看不到这里发生了什么。

那是我的控制器,具有以下端点:

@GetMapping("/api/getAge")
public int getAge (@RequestParam("person") Person p) {
    return this.computeAge(p);
}

计算年龄的方法(显然)返回人的年龄。问题是:当我使用邮递员到这条路线时,该方法运行但我得到一个 http 错误 405。

标签: apispring-boothttp

解决方案


您缺少@ResponseBody注释:

@GetMapping("/api/getAge")
@ResponseBody
public int getAge (@RequestParam("person") Person p) {
    return this.computeAge(p);
}

推荐阅读