首先声名,这些东西都不是我原创的哈,我只是一个互联网的搬运工:)
老外的回答,这也是最方便的用法
While it's true that @RequestBody must map to a single object, that object can be a Map, so this gets you a good way to what you are attempting to achieve (no need to write a one off backing object):
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody Map<String, String> json) {
//json.get("str1") == "test one"
}
You can also bind to Jackson's ObjectNode if you want a full JSON tree:
public boolean getTest(@RequestBody ObjectNode json) {
//json.get("str1").asText() == "test one"
或者也可以用匿名类
@Controller
public class TestController{
@RequestMapping("\test")
@ResponseBody
public RetureResult test(@RequestBody Param param){
return new ReturnResult();
}
}
class Param{
public User user;
public Address address;
}
来自:https://www.cnblogs.com/mahuan2/p/6008832.html