java当post请求在postman中完成时,它会将所有值传递为NULL
This is my back end where the method is taking a student object and a String Id.
@PostMapping(path="/edit/student")
@RequestMapping(value = "/edit/student", method = RequestMethod.POST)
public void editStudent(@RequestBody Student student,String id){
ss.editStudent(student,id);
}
When I try to do a post request using postman it sends null for everything.
{
"student":{
"firstname": "jay",
"lastname": "patel",
"studentId": "2",
"email": "temp163@gmail.com"
},
"id":"1"}
Check this out. this may help a little to understand. Backend gets everything as null.
This is the post-call from the postman. Postman call
# 1 楼答案
它看起来像是作为POST有效负载发送的JSON,而不是学生对象的表示形式。相反,它是一个包含两个成员的对象的表示,一个名为
student
的学生对象和一个名为id
的字符串如果将该有效负载反序列化为Java类,它将如下所示:
简而言之,您的REST端点需要一个Student对象,但这不是您提供给它的,它无法将这个“SomeObject”表示反序列化为Student的实例
尝试将有效负载更改为端点期望的学生对象的表示形式: