首页 > 代码库 > The request sent by the client was syntactically incorrect. 400 问题

The request sent by the client was syntactically incorrect. 400 问题

  The request sent by the client was syntactically incorrect.

  这个问题是因为 SpringMvc controller 里面的方法参数和请求参数不匹配。

 

请求参数在 Contoller 的方法参数对象中不存在则会报这个错误。

如 :

  Controller 里面的方法

@RequestMapping(value = "http://www.mamicode.com/login/signin", method = RequestMethod.POST)    public @ResponseBody Person login(HttpServletRequest request, @RequestBody Person person){ //...       }
public class Person { private int id; private String name;       //... set get}
function init() {      var url = "login/signin";      var req = new Object();
    req.id = 1; req.name = "aaa"; req.age = 18
; // Person 没有age 属性. (function() { $.ajax({ type : ‘post‘, url : url, contentType : ‘application/json‘, datatype : ‘json‘, data : JSON.stringify(req), success : processSuccess, error : processError }); })(); function processSuccess(result) { alert("success--"+result); } function processError(result) { alert("error--"+result); } }

 

The request sent by the client was syntactically incorrect. 400 问题