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

背景

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

Postman:
postman
请求参数:

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

Controller:
controller

Entity
model
通过debug模式可以发现传进到实体的参数都为null

解决思路

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

 //@JsonProperty(value = "firstName")

model2

修改后结果:

postman2

发布了121 篇原创文章 · 获赞 330 · 访问量 40万+

猜你喜欢

转载自blog.csdn.net/Evan_Leung/article/details/101687904