我正在向控制器发布JSON对象,它显示404错误,并显示消息“客户端发送的请求在语法上不正确”。
<html>
<form action= "action" method="post">
<input type ="text" name="user.name"/>
<input type ="text" name="user.pwd"/>
</form>
</html>
并抓住控制器
@RequestMapping(value = "/action", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
public @ResponseBody
public void createuser(@RequestBody UserDTO request,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
..........
}
我的问题有两个原因
1.我们需要使用服务器端DTO检查传递的属性。如果有任何误解,则提示此错误
2.我们传递给服务器的所有属性都应在DTO中显示。如果出现任何其他可能导致错误的属性,则需要从json对象中删除attibute,例如delete jsonObject.extra对象
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句