api - GetMapping 在 Spring Boot 中返回错误 405
问题描述
我有一个在服务器端使用 Spring Boot 的系统。我收到一个错误,我看不到这里发生了什么。
那是我的控制器,具有以下端点:
@GetMapping("/api/getAge")
public int getAge (@RequestParam("person") Person p) {
return this.computeAge(p);
}
计算年龄的方法(显然)返回人的年龄。问题是:当我使用邮递员到这条路线时,该方法运行但我得到一个 http 错误 405。
解决方案
您缺少@ResponseBody
注释:
@GetMapping("/api/getAge")
@ResponseBody
public int getAge (@RequestParam("person") Person p) {
return this.computeAge(p);
}
推荐阅读
- c# - 发布应用程序并包含 .dbo 和表格?
- ionic4 - Ionic4 滑动项问题
- html - 修复手机图像并减少放大问题
- wordpress - WP2Static cURL 错误:无法解析主机:statics.mydomain.com
- python - HarfBuzz language_from_string Python自省方法不接受str
- bash - 理解 bash if 语句中的 -f
- julia - 在 JULIA 的分布式 for 循环中写入共享数组
- php - FPDF:使用 MultiCell 时,如果有分页符,插入行无法正常工作
- reactjs - 如何在 ReactJS 中保存输入默认值
- git - 为什么最近, git rebase -i squash 导致头部分离