Send js list to a Spring Java controller

0

I hope to receive a list in my controller that is sent by ajax , in Java but I get an error:

  

Non-type collection, that is, it does not match.

Any other way to stop it?

JavaScript

var itms = [];
for (i = 1; i < 10; i++) {
    var obj = {};
    obj['cantidadD'] = i;
    obj['unidadD'] = 'kg';
    itms.push(obj);
}

$.ajax({
    url: 'genimp',
    type: 'GET',
    data: {itm: itms},
    success: function (r) {

    }
});

Driver

//public @ResponseBody Map<String, Object> genfacturaimp(List itm){
public @ResponseBody Map<String, Object> genfacturaimp(ArrayList itm){
    Map<String, Object> map = new HashMap();
    map.put("fn", itm.size());
    map.put("l", 1);
    return map;
}
    
asked by user75463 03.07.2018 в 18:10
source

1 answer

0

Your driver is waiting for a list, but your JavaScript code sends an object:

...
data: {itm:itms}
...

If you directly send the array created:

... 
data: itms
...

It should work.

    
answered by 03.07.2018 в 18:17