springboot front end passes the received list set of problems such as complex objects to the rear

 Transfer: https://blog.csdn.net/qq_27093465/article/details/52094112

https://www.cnblogs.com/yfzhou/p/9661994.html

spring MVC background processing array object.

list types of parameters, an array of values received front desk, experiment a bit, the results really can be.
Do not bind to the object inside.
This is the course I passed the front desk is included in a string array to the background, then the background with a list to receive.
details as follows:

Front Code:

// send back, with an array of data to the request.
testlist function () {
var = getTreeViewCheckedData Data ();
$ .ajax ({
URL: APP_NAME + "XXXX / testlist",
Data: {
List: Data
},
dataType: "JSON",
Success: function (Data) {
}
} );
}
// --- obtain data stored in the form of an array of
function getTreeViewCheckedData () {
var checkedData = [];
$ ( '# shareSetting') Find (. 'ol.bonsai INPUT: CheckBox: the checked') each (. function () {
checkedData.push ($ (the this) .val ())
}
);
return checkedData;
}

Background Code:
// one embodiment, an array of parameters received by the reception list.
@RequestMapping (value = "/ testlist")
@ResponseBody
public a JsonResult testlist (@RequestParam (= required to false, value = "List []") List <String> List) {
log.debug ( "------- XxxxController --------: testlist --------------- ");
log.debug (" --------------- List : \ T "+ List);
return a JsonResult new new (to true," OK ", null);
}

// Second way, an array of parameters received by the reception array. Then converted into a list, though not necessary.
@RequestMapping (value = "/ testlist")
@ResponseBody
public a JsonResult testlist (@RequestParam (= required to false, value = "List []") String [] List) {
log.debug ( "-------- XxxxController -------: testlist --------------- ");
log.debug ("
List<String> newList = Lists.newArrayList(Arrays.asList(list));
return new JsonResult(true,"ok ",null);
}

Note specific region:

value = "list [], this seems to not be spared,

In addition, if you modify parameters on the method, then you have to restart it, or not value

The list of data to and reception of exactly the same.


----------------
Disclaimer: This article is the original article CSDN bloggers "Li Xuekai", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/qq_27093465/article/details/52094112

 

 

 

JS front-end

Copy the code
 1 var taskList = ["123","456"];
 2 var params = {
 3     taskList: taskList
 4 };
 5 
 6 $.ajax({
 7     type: "PUT",
 8     dataType: "json",
 9     url: "/client/update",
10     data: params,
11     success: function (msg) {
12     }
13 });
Copy the code

Back-end reception:

1 @RequestMapping(value = "/update", method = RequestMethod.PUT)
2 @ResponseBody
3 public JSONResult updateClient(Client client, @RequestParam(value = "taskList[]") List<String> taskList) {
4     logger.debug("Yufan taskList={}", taskList);
5     return JSONResult.ok();
6 }

References: Spring pass the MVC reception array type, list type receiving background are possible

Blog content are my learning record, is not guaranteed correct, if wrong, please correct me.

Guess you like

Origin www.cnblogs.com/linwenbin/p/11447942.html