Problem Description:
Have declared
@RequestMapping (value= "Update", method = Requestmethod.post)
@ResponseBody
Public map<string, result> Updatenavi (@RequestBody Navigation model)
The boot logs are:
Mapped "{[/navi/update],methods=[post],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public Java.util.map<java.lang.string, com.apusic.ebiz.framework.web.controller.result> Com.mm.NavigationController.updateNavi (com.mm.navigation.Navigation)
Perform
$.postjson (' Http://localhost:8082/mm/navi/update ', {a:1})
reported 400 errors.
and
$.postjson (' Http://localhost:8082/mm/navi/update ', {})
Nothing wrong.
His uncle, who has been using this method before, submits the form completely normal. Damn it.
Wrong row
1. The console does not have any information, that the request is not in the system, to be Tomcat file, suspected of web.xml,spring-mvc.xml and other configuration issues
But modifying the n-parameters of the WEB.XML,SPRING-MVC has no effect. But think, before all can succeed, why suddenly not succeed, strange.
2. The data of the suspected post is not in JSON format, and is specifically compared to a JSON format that can be successfully submitted. This is a dumbfounded,
3. Why is the empty JSON construct successful? Request directly to the controller, do not know
4. When I try to use
$.postjson (' Http://localhost:8082/mm/navi/update ', "")
It actually error, originally, he entered the system, returned to Tomcat, so Tomcat only error 400
Decisive in Org.springframework.web.servlet.DispatcherServlet.doDispatch (HttpServletRequest, httpservletresponse) break point
Sure enough, come in, step by step with, found the following log.debug, the original has a log, and my console did not log, depressed, a look at log4j, sure enough is the info level of the other
Solve:
Open log4j to Org.springframework.web=debug
Request again
$.postjson (' Http://localhost:8082/mm/navi/update ', {a:1})
I finally saw the anomaly.
Resolving exception from Handler org.springframework.http.converter.HttpMessageNotReadableException:Could not read json:unrecognized Field "A" (Class com.mm.navigation.Navigation), not marked as ignorable
At [Source:org.apache[email protected]; Line:1, Column:7] (through reference chain:com.apusic.mm.navigation.Navigatio N["a"]); Nested exception is org.codehaus.jackson.map.exc.UnrecognizedPropertyException:Unrecognized field "a" (Class com.mm.navigation.Navigation), not marked as ignorable
at [Source: [email protected]; line:1, Column:7] (through reference chain:com.apusic.mm.navigation.navigation["a"])
Before the exception has been eaten by spring, annoying ah.
The original is the entity navigation without a attribute, the conversion is unsuccessful, throw an exception, but by spring to 400 error, simple thrown out, spring honest ah.
Request the parameters again,
$.postjson (' Http://localhost:8082/mm/navi/update ', {id:1})
That's good enough.
Just write this, share, inspire, although the problem is simple, but sometimes the brain is easy to short-circuit, find no point.
Report:
$.postjson = function (URL, data, callback) {
Return Jquery.ajax ({
' type ': ' POST ',
' url ': URL,
' ContentType ': ' Application/json ',
' Data ': json.stringify (data),
' DataType ': ' JSON ',
' Success ': Callback
});
};
Fix Spring mvc3.1 post JSON appears HTTP Status sent by the client was syntactically incorrect