Ajax pass the array to the background, the background Spring MVC accepts an array of parameters

The front end of the following code, passing an array, receiving background List <String>:

var arrayData = [];
arrayData.push("xxx");
arrayData.push("yyy");
$.post(url,{arrayData : arrayData},function(data,status) {
    //do something
});

Background code as follows:

@RequestMapping("test")
@ResponseBody
public Message test(@RequestParam(value="arrayData[]") List<String> arrayData){
    //do something
    return data;
}

There are two points to note:

  1. Use annotations@RequestParam
  2. Parameter values ​​annotation in to add[ ]

Note: if arrayData only one value, and this value has a comma, for example:

arrayData.push("xxx,yyy")

Such data, when received back, list there will be two elements, namely "xxx" and "yyy"

If there are a plurality of deployment arrayData values, for example:

arrayData.push("xxx,yyy")

arrayData.push("aaa,bbb")

Such data, received the background, it does not split apart, that list there will be two elements, namely, "xxx, yyy" and "aaa, bbb";

So, if by virtue of their own data, so try not to use a comma; if you want to transfer the data itself, so, it can be replaced with other characters first comma, and then the background reception, back to back.

Intelligent Recommendation

SpringMVC pass parameters via ajax list objects or background objects to pass array

surroundings Reception to pass parameters to the background Reception using ajax Background use springMVC Transmission parameters are a plurality of objects N JSON object and JSON string In SpringMVC ...

Js way to pass array parameters to the background controller

Sharing a js method of passing array parameters to the background controller has a good reference value and I hope to help everyone. passes the arguments to the string, so to convert the array to a st...

axios pass the array parameters, the background cannot be received

Regarding the tone of the front and back end, the parameters cannot receive the problem. If you encounter a back end of the color pen, the parameter format is not clear about the interface document an...

Java background accepts jQuery's ajax parameters

Preface As a front-end entry library, jQuery is one of the necessary skills for every front-end staff. The $.ajax() method in jQuery is one of the basic methods for data transmission between front and...

Background mvc receives array parameters, Postman test

Postman correctly tests passing arrays, MVC receives array parameters Receive parameter @RequestParam ("ids") in the background Postman test The value of the array, the name needs to corresp...

More Recommendation

Passing array parameters to the background via ajax

When using ajax to pass values ​​to the background, sometimes a field needs to pass multiple values, you need to use an array. By default, ajax's parameter traditional is false, ie jquery will deeply ...

Ajax solution when sending an array of parameters to the background

Introduction: In many cases, the front desk parameter passed is an array, then spliced ​​into a bad string of key parameters, it can be resolved as follows: 1, add "traditional:true"Paramete...

Spring mvc background directly accepts beans and lists

1. Convert to bean Front page js Code behind 2. Convert to list Note that to convert to list, you need to pass an array in the foreground, and use the List directly to receive in the background, as fo...

How to pass values ​​to the background without Ajax Spring MVC

Idea: 1, the data to be transferred into the array 2, create a hidden form 3. Traverse the array, create a hidden <input> in the hidden form and assign it 4, submit the form  ...

Django accepts an array ajax pass over

js: $.ajax({ cache: false, type: "POST", url: "/userdelete/", traditional: true, // add this to pass an array dataType:'json', async: true, data:{ids:ids}, success: function(data) ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top