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

it2022-05-05  111

  The request sent by the client was syntactically incorrect.

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

 

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

如 :

  Controller 里面的方法

@RequestMapping(value = "/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); } }

 

转载于:https://www.cnblogs.com/shouwangzhe-/p/3936675.html


最新回复(0)