将json发布到spring mvc控制器
控制器签名(我也尝试过请求者):
@RequestMapping(value = "/Lame", method = RequestMethod.POST) public @ResponseBody boolean getLame(@RequestParam String strToMatchA, @RequestParam String strToMatchB) {}
这是我的json:
{ "strToMatchA": "EN", "strToMatchB": "lon" }
不工作,我收到错误:
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'strToMatchA' is not present
从方法签名中删除第一个参数然后使其工作(方法被正确调用),我该怎么办?
当我更改要使用@RequestBody
注释的方法参数时,我收到以下错误:
java.io.IOException: Stream closed
你的json很好但不是控制器签名。 使用与json匹配的setter创建一个类。 使用它作为参数而不是字符串。 用requestbody注释它。 它应该工作。