是否有必要包裹背衬物体?我想做这个:
@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.
我想知道例如SpringMVC控制器是否可以有方法签名,例如
@RequestMapping(value = "/target", method = RequestMethod.POST)
@ResponseBody
public void acceptObject(@RequestBody MyObjectDto dto,@RequestBody String messageBody) {
//Authenticate messageBody
//Process mapped DTO
}
Run Code Online (Sandbox Code Playgroud)
目的是将JSON发布到此控制器,原始消息体将进行身份验证以确保完整性,如果正确,则JSON将映射到可以切换以进行处理的DTO.
目前我最终得到了
java.io.IOException: Stream closed
Run Code Online (Sandbox Code Playgroud)