I'm trying to retrieve a list of javascript objects in Java Spring MVC but when it arrives to the controller is empty.
I've been reading a lot about but I don't know how it works
This is my ajax code:
$.ajax({
url : 'ajax/abrir_cotizacion',
data : {
listaunidades: [{
idtipounidad: 1,
modelo: 2013,
cantidad: 1,
tipopago: 1,
costounidad: 1500000,
ivaoperacion: 25000,
totaloperacion: 1504000,
enganche: 750000,
idplazo: 3
},
{
idtipounidad: 2,
modelo: 2012,
cantidad: 2,
tipopago: 2,
costounidad: 1500000,
ivaoperacion: 25000,
totaloperacion: 1504000,
enganche: 750000,
idplazo: 6
}]
},
type : 'POST',
dataType : 'json',
success : function(data) {
},
error : function(xhr, status) {
alert('Disculpe, existió un problema');
},
complete : function(xhr, status) {
//alert('Petición realizada');
}
});
And below my controller and model required to this.
@ResponseBody
@RequestMapping(value = "/ajax/abrir_cotizacion", method = RequestMethod.POST)
public Object abrircotizacion(Model model, HttpServletRequest request, @ModelAttribute ArrayList<Unidades> listaunidades) {
try {
Injector inj = AppInjector.getInjector();
return new MsgPojo(1, "Se abre la cotización");
} catch (Exception ex) {
LoggerUtils.printLog(this.getClass(), Level.SEVERE, ex, null, Thread.currentThread().getStackTrace());
return new MsgPojo(-1, "Ocurrio un error al cargar los datos. " + ex.toString());
}
}
public class Unidad {
private int idtipounidad;
private int modelo;
private int cantidad;
private int tipopago;
private double costounidad;
private double ivaoperacion;
private double totaloperacion;
private double enganche;
private int idplazo;
//getters and setters
}