First, look at an exception:
Org.springframework.http.converter.HttpMessageNotReadableException:Could not read document:unrecognized token ' Entitylist': Was expecting (' true ', ' false ' or ' null ')
The attribute values that are defined in the entity are marked as follows:
@Data Public class COLUMNSVO { Listnew arraylist<>();}
View Code
Front-end JS code:
$.ajax ({
URL: ' Grid/add.columns ',
Type: "POST",
Data: {
Entitylist:rows
},
Success:function (data) {
Layer.msg (Data.message);
},
DataType: "JSON",
ContentType: "Application/json"
});
Controller processing Code:
@RequestMapping (value = "/add", consumes = "application/json; Charset=utf-8 ") public easyuiresponse addcolumns (@RequestBody columnsvo columnsvo) { System.out.println (json.tojsonstring (COLUMNSVO)); return New Easyuiresponse (easyuiresponse.success, "Configuration succeeded! "); }
View Code
Before $.ajax data has been using {Key:value} way, this time is no exception, the result is an error ...
Search, find after solution:
$.ajax ({
URL: ' Grid/add.columns ',
Type: "POST",
Json.stringify ({
Entitylist:rows
}),
Success:function (data) {
Layer.msg (Data.message);
},
DataType: "JSON",
ContentType: "Application/json"
});
And above, only a little difference, the {key:value} using Json.stringify ({Key:value}) converted to a string, everything is OK!
A rather strange question, remember ...
Another: points to note in spring MVC for incoming collections:
1, look at the code:
consumes = "Application/json; Charset=utf-8 ")
Public Easyuiresponse addcolumns (@RequestBody columnsvo columnsvo) {
System.out.println (json.tojsonstring (COLUMNSVO));
return new Easyuiresponse (easyuiresponse.success, "Configuration succeeded! ");
}
Mark parts need attention!
2, is the above discussion section, the attention!
An attempt to remember the introduction of spring MVC into list<object>