An attempt to remember the introduction of spring MVC into list<object>

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.