js前端ajax提交list集合参数至后端

            var orderNosList = new Array();
var rows = $("#dg_linkOrder").datagrid("getChecked");
if(rows.length < 1){
$('#error').dialog('open').dialog('center').dialog('setTitle', '错误提示');
$('#error').text("请选择一条数据");
}else {
for (var i = 0; i < rows.length; i++) {
orderNosList[i] = rows[i].orderNo;
} var params = {
reserveOrderNoList:orderNosList
}; $.ajax({
url : api.LINK_ORDER_RESERVE_RETRY,
data : JSON.stringify(params),
type : 'POST',
contentType: "application/json",
dataType : 'json',
success : function(res) {
var str = '';
$(res.reserveFlowList).each(function(i, obj){
var responseCode = obj.responseCode;
var orderNo = obj.reserveFlow.orderNo;
if (responseCode == 0) {
str += "订单号为"+ orderNo +"成功<br/>";
} else {
str += "订单号为"+ orderNo + obj.responseMsg +"<br/>"
}
}); $('#error2').dialog('open').dialog('center').dialog('setTitle', '提示');
$('#error2').html(str);
// 刷新列表
linkOrder.unfresh_LinkOrder();
}
});
}

JAVA后端

    @RequestMapping("/http/pss/reserveOrderRetry")
@ResponseBody
public Object reserveOrderRetry(@RequestParam("reserveOrderNoList")List<String> reserveOrderNoList) {
return service.reserveOrderRetry(reserveOrderNoList);
}

JS

var demo = new Object();
demo.name="1";
demo.id="2";
var demo2 = new Object();
demo2.name="1";
demo2.id="2"; var conditons = [];
conditons.push(demo);
conditons.push(demo2); $(function(){
  $.ajax({
    type:'post',
    url:'/http/pss/demo',
contentType: "application/json",
    data:{name:"123",conditions:JSON.stringify(conditons)},
    dataType : 'json',
    success:function(data){
      console.log(data);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown){
      alert("error");
    }
  });
});
    @RequestMapping("/http/pss/reserveOrderRetry")
@ResponseBody
public Object reserveOrderRetry(@RequestParam("conditions")List<Demo> conditions,
@RequestParam("name")String name) { }
上一篇:NOIP2013


下一篇:【转】随机函数的rand、srand用法