今天在调试项目的时候遇到一个坑,用Postman发送一个post请求,在Springboot项目使用@RequestBody接收时参数总是报不存在,但是多次检查postman上的请求格式以及项目代码都没有问题

Postman:
Springboot | @RequestBody 接收到的参数对象属性为空
请求参数:

{
	"firstName":"fdsaf",
	"lastName":"dfasdf"
}

Controller:
Springboot | @RequestBody 接收到的参数对象属性为空

Entity
Springboot | @RequestBody 接收到的参数对象属性为空
通过debug模式可以发现传进到实体的参数都为null

解决思路

经过分析,有可能是springboot解析器在解析json过程中出现问题,因字段名驼峰命名无法匹配字段名导致,加上如下注解即可:

 //@JsonProperty(value = "firstName")

Springboot | @RequestBody 接收到的参数对象属性为空

修改后结果:

Springboot | @RequestBody 接收到的参数对象属性为空

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
猜你喜欢
  • 2021-05-07
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-11-20
  • 2021-11-22
相关资源
相似解决方案