The project used AJAX for page data list refresh, call need to use a lot of query conditions, the previous practice is to use @requestparam to get the incoming parameters, but more parameters, the number of @RequestParam will be more and more, You can use @requestbody to receive the list of parameters in Jason format and automatically convert to a custom object, but you need to introduce Jackson
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactid>json-path</ artifactid>
<version>0.8.1</version>
<scope>test</scope>
</ dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
< artifactid>jackson-core-lgpl</artifactid>
<version>1.8.5</version>
</ dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
< artifactid>jackson-mapper-lgpl</artifactid>
<version>1.8.5</version>
</ Dependency>
This is written in Ajax: The field in the red font is the same as the fields in the Java bean, so that Jackson can automatically convert
function GetPageSize () {
$.ajax ({
type: Post),
async:false,
url: ' getpagesize ',
data: Json.stringify ({
SourceID: $ ("#source"). Val (),
Seriesid: $ ("#series"). Val (),
modelid: $ ("#model"). val (), City
: $ ("#city"). Val (),
strfrom: $ ("#from"). Val (),
Strto: $ ("#to"). Val ()
}),
DataType: "JSON",
contentType: "Application/json;" Charset=utf-8 ",
success:function (data) {
...}
,
error:function (data) {
...
}}
);
}
This is written in spring controller:
@RequestMapping (value = "/queryinfo", method = Requestmethod.post)
@ResponseBody public
list<record> QueryInfo (@RequestBody searchcondition condition) {
//...
}
This allows the Ajax data to be converted to Java objects, without a single parameter to get.