是否有必要包裹背衬物体?我想做这个:
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody String str1, @RequestBody String str2) {}
Run Code Online (Sandbox Code Playgroud)
并使用这样的JSON:
{
"str1": "test one",
"str2": "two test"
}
Run Code Online (Sandbox Code Playgroud)
但相反,我必须使用:
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody Holder holder) {}
Run Code Online (Sandbox Code Playgroud)
然后使用这个JSON:
{
"holder": {
"str1": "test one",
"str2": "two test"
}
}
Run Code Online (Sandbox Code Playgroud)
那是对的吗?我的另一个选项是改变RequestMethod到GET和使用@RequestParam的查询字符串,或者使用@PathVariable与两种RequestMethod.