英文:
@RequestBody is fetching null values
问题
@PostMapping("/req")
public String message_handler(@RequestBody messageStructure ingress_req_msg) {
System.out.println("Inside message_handler");
System.out.println(ingress_req_msg); // always print null
return "Welcome";
}
class messageStructure
{
String MsgData;
//getters and setters are there
//Constructor
public messageStructure(messageStructure req)
{
MsgData = req.getMsgData();
}
}
Postman Request Syntax:
{
"MsgData":"Sample Message Data",
}
英文:
@PostMapping("/req")
public String message_handler(@RequestBody messageStructure ingress_req_msg) {
System.out.println("Inside message_handler");
System.out.println(ingress_req_msg); // always print null
return "Welcome";
}
class messageStructure
{
String MsgData;
//getters and setters are there
//Constructor
public messageStructure(messageStructure req)
{
Msgdata = req.getMsgdata();
}
}
Postman Request Syntax:
{
"MsgData":"Sample Message Data",
}
- Tried to check dependencies.
- Refreshed gradle dependencies.
- Rechecked class variable Names messageStructure
- Set the same json content values
{ "MsgData":"example.test.co"}
答案1
得分: 1
确保您导入了正确的 @RequestBody
注解:
import org.springframework.web.bind.annotation.RequestBody;
英文:
Make sure you imported the right @RequestBody
annotation:
import org.springframework.web.bind.annotation.RequestBody;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论