标签:
需求:从页面提交一个table中的数据到后台,通常用于批量修改
把所有的数据到放到 input属性中,设置name定义成为对象的相关属性,使用Jquery的serializeArray这个方法封装成为对象,具体实现参考代码
$.post("radixAdjustAll.do", $("#fm").serializeArray(),function(flag){ if(flag="true"){ var url=window.location.href; window.location.href=url; }else{ var ctn = "<div class='title'>保存失败!</div>"; ResultUtils.showError({ dialog:dlg, content:ctn }); } });
</pre><pre name="code" class="javascript">
</pre><pre name="code" class="java"> <#assign index = 0 /> <#if products.list?size gt 0> <#list products.list as partner> <tr class="${partner[0].no}${index}"> <td align="center">${partner[0].applyerCode}</td> <td>${partner[0].applyerName}</td> <td align="center">${partner[0].bigAreaName}</td> <td align="center">${partner[0].areaName}</td> <td id="td" value="aa" width="50px"> <input readOnly="true" type="text" name="partnerProducts[${index}].stockMin" class="min u-text2 required" value="${partner[1].stockMin}" style="width:40px;text-align: right;"/></td> <td><input readOnly="true" type="text" name="partnerProducts[${index}].stockMax" class="max u-text2 required" value="${partner[1].stockMax}" style="width:40px;text-align: right;"/></td> <td><input type="text" name="partnerProducts[${index}].radixMin" class="radixMin u-text2 required" value="${partner[1].radixMin}" style="width:40px;text-align: right;"/></td> <td><input type="text" name="partnerProducts[${index}].radixMax" class="radixMax u-text2 required" value="${partner[1].radixMax}" style="width:40px;text-align: right;"/></td> <td><input type="text" name="partnerProducts[${index}].stockAvg" class="stockAvg u-text2 required" value="${partner[1].stockAvg}" style="width:40px;text-align: right;"/></td> <td><input type="text" name="partnerProducts[${index}].divideQuantity" class="divideQuantity u-text2 required" value="${partner[1].divideQuantity}" style="width:40px;text-align: right;"/></td> <td><input type="text" name="partnerProducts[${index}].startDt" value="${(partner[1].startDt?string('yyyy-MM-dd'))!}" class="ui-datepicker-input u-text2 startDt"/></td> <td><input type="text" name="partnerProducts[${index}].invalidDt" value="${(partner[1].invalidDt?string('yyyy-MM-dd'))!}" class="ui-datepicker-input u-text2 invalidDt"/></td> <td class="center"> <input type="hidden" name="partnerProducts[${index}].id" value="${partner[1].id}" /> <a class="sbmit" date-id="${partner[1].id}" value="${partner[0].no}${index}" style="cursor: hand;cursor: pointer;">保存</a> <!-- | <@ui.auth code='/product/abateStockProduct.do'><a class="abate" value="${partner[1].id}" style="cursor: hand;cursor: pointer;">失效</a></@ui.auth> --> </td> </tr> <#assign index=index +1 /> </#list> </#if>
@RequestMapping(value = "/radixAdjustAll.do", method = RequestMethod.POST) @ResponseBody public String radixAdjustAll(PartnerProduct partnerproduct) { try { service.updateRadixAdjustAll(partnerproduct.getPartnerProducts()); return "true"; } catch (Exception e) { e.printStackTrace(); return "false"; } }
SpringMvc参数的接受以及serializeArray的用法
标签:
原文地址:http://blog.csdn.net/h249059945/article/details/47123765