springMVC background process array objects.
List type parameter, receive the array value of the front desk, and after experimenting, the result is really OK.
No need to bind to the object.
Of course, I passed an array containing string to the background, and then used list to receive it in the background.
The details are as follows:
Front Desk Code:
//Send requests to the background, with data in array form. function testList() { var data = getTreeViewCheckedData(); $.ajax({ url: APP_NAME + "xxxx/testList", data: { list:data }, dataType: "json", success: function (data) { } }); } //Get data ---Storage function getTreeViewCheckedData() { var checkedData = []; $('#shareSetting').find('ol.bonsai input:checkbox:checked').each(function () { checkedData.push($(this).val()) } ); return checkedData; }Background code:
//Method 1: Use list to receive the array parameters of the front desk. @RequestMapping(value = "/testList") @ResponseBody public JsonResult testList(@RequestParam(required = false, value = "list[]") List<String> list){ LOG.debug("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Then convert it to a list, although it is not necessary. @RequestMapping(value = "/testList") @ResponseBody public JsonResult testList(@RequestParam(required = false, value = "list[]") String[] list){ LOG.debug("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- JsonResult(true,"ok",null); }Notes:
value="list[], this seems to be unsavory.
In addition, if you modify the parameters on the method, you have to restart it, otherwise you won't get the value
This list should be exactly the same as the data in the front desk.
Summarize
The above is all the content of this article about the springMVC front-end transmission array type and the background using list type to receive instance code. I hope it will be helpful to everyone. Interested friends can continue to refer to this site:
Detailed explanation of whether the SpringMVC interceptor implements monitoring session expires
Detailed explanation of user query code for SpringMVC development restful API
Spring SpringMVC performs method source code analysis after startup is completed
If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!