This is the low-level mistake I made when I personally wrote the blog system because of personal negligence.
But it's a good thing to make a mistake and help summarize.
1. Add @requestbody before parameter
If you are using AJAX interaction, you must add this contenttype: ' Application/json;charset=utf-8 '
Otherwise, this exception will occur:
Error message: org.springframework.web.HttpMediaTypeNotSupportedException:Content type ' application/x-www-form-urlencoded; Charset=utf-8 ' not supported
This type of delivery is not supported because it is not defined in the foreground and indicates that the content passed must be JSON. Sometimes special backstage with @requestbody as the parameter, must add contenttype in Ajax: ' Application/json;charset=utf-8 ', plus this means that you have passed the object defined as a JSON type, @ Requestbody also supports only JSON types. So it is easy to understand why this error occurred. In particular, we are the developers of the army, many of whom have such a person, for never encountered errors, copy paste to Baidu to search, usually before people have encountered, through the form of blog to record the error message and how to solve it, and why it happened. But some of our friends only look at how to solve, as to why it will happen never to ignore.
Error message: Org.springframework.http.converter.HttpMessageNotReadableException:JSON parse error:unrecognized token ' email ': Was expecting (' true ', ' false ' or ' null '); Nested exception is com.fasterxml.jackson.core.JsonParseException:Unrecognized token ' e-mail ': Was expecting (' true ', ' False ' or ' null ')
This error is due to the fact that the JSON object parameters you have defined are not fully written, and this error is caused by the @requestbody receive parameter in the background, must be written in the data corresponding value in Ajax json.stringify
Example:
That's right, it's not going to happen.
$.ajax ({url: "/blog-web/user/register", type: "POST", ContentType: ' Applicatio N/json;charset=utf-8 ', data:JSON.stringify (data), DataType: ' JSON ', succes S:function (data) {if (data.returncode== "333333") {layui.use (' layer '), function () {var layer = Layui.layer; Layer.alert (data.returnmsg, {icon:5}); }); }else if (data.returncode== "222222") {layui.use (' layer ', function () { var layer = Layui.layer; Layer.alert (data.returnmsg, {icon:5}); }); }else if (data.returncode== "111111") {layui.use (' layer ', function () {var LAyer = Layui.layer; Layer.alert (data.returnmsg, {icon:5}); }); }else if (data.returncode== "000000") {layui.use (' layer ', function () { var layer = Layui.layer; Layer.alert ("Please come in Soon" +data.returnmsg,{icon:1}); }); SetTimeout (() = {view (); }, 10000); }},error:function () {layui.use (' layer ', function () {var layer = Layui.layer; Layer.alert ("with exception, please contact the Administrator"); }); } });
Springmvc and Ajax Interactions FAQ