@RequestBody获取到了空值

huangapple go评论79阅读模式
英文:

@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",
}
  1. Tried to check dependencies.
  2. Refreshed gradle dependencies.
  3. Rechecked class variable Names messageStructure
  4. 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;

huangapple
  • 本文由 发表于 2023年1月6日 13:55:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定