// 产品列表 var productList = []; // 仓库ID var stockId = $('#stock').val(); // 循环往数组中添加复杂数据项 $.each($('#ul li'), function(i, ele){ productList.push({ product:{ id : $(ele).find('.productid').val(), }, quantity: $(ele).find('.quantity').html(), produceDate: $(ele).find('.date').html() + " 00:00:00", warehouse : { id : stockId } }); }); // 创建数据实体,与后台实体类对应 var obj = { products:productList }; // ajax传输数据往后台 $.ajax({ contentType : 'application/json;charset=utf-8', url: '${ctx}/wx/addProduct', type: 'POST', data : JSON.stringify(obj), dataType:"json", success: function (ret) { console.info('success'); } });
@RequestMapping(value = "${adminPath}/wx/addProduct",method=RequestMethod.POST) @ResponseBody public String addProduct(@RequestBody Warehsave warehsave,Model model) { return "weixin/select_product"; }
public class Warehsave{ private List<WarehouseIn> products; public List<WarehouseIn> getProducts() { return products; } public void setProducts(List<WarehouseIn> products) { this.products = products; } }