【发布时间】:2019-05-24 00:44:45
【问题描述】:
我正在尝试检索 Java Spring MVC 中的 javascript 对象列表,但当它到达控制器时为空。
我已经阅读了很多关于但我不知道它是如何工作的
这是我的 ajax 代码:
$.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');
}
});
在我的控制器和模型下面需要这个。
@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
}
【问题讨论】:
标签: javascript java jquery ajax spring-mvc