如下所示:
JSPvar vipFee= new Array;//遍歷選中的對象$("#feeList :checkbox:checked").each(function(i){ vipFee.push({"enterpriseSeq":$(this).attr("enterpriseSeq"),"merchNo":$(this).val(),"serviceFee":$(this).attr("fqbFee")}); });//進行異步$.ajax({ type:"POST", url: "addVipFeeList", async:false, dataType:"json", contentType:"application/json", // 指定這個協議很重要 data:JSON.stringify(vipFee), success:function(data){ //判斷是否是成功的返回的 if(data.success===true){ $("#feeList :checkbox:checked").each(function(i){ var FQBFee = parseFloat($(this).parent().siblings("td").find("input[name='fqbFee']").val()); $(this).parent().siblings("td").find("input").attr("readonly","readonly"); $(this).parent().siblings("td").find("input[name='fqbFee']").val(FQBFee.toFixed(3)); //將“取消定價”,進行顯示 $(this).parent().siblings("td").find("a[id='cancelA']").show(); //將“確定定價”進行隱藏 $(this).parent().siblings("td").find("a[id='relateA']").hide(); //取消掉選中的狀態 $(this).prop("checked", false); }); } } }); Controller @RequestMapping(value = Constants.ADMIN + "/addVipFeeList",method=RequestMethod.POST) @ResponseBody public Map<String,Object> addVipFeeList(@RequestBody List<VipFee> vipFee){ Map<String,Object> map=new HashMap<String,Object>(); try { //判斷對象是否為空 if (vipFee!=null&&vipFee.size()>0) { //進行遍歷并賦值 for (VipFee v:vipFee) { v.setReplacePrdId(Constants.PRODUCT_TYPE_FQB); } } //進行添加 vipFeeService.addVipFeeList(vipFee); map.put("success", true); } catch (CoreException e) { map.put("success", false); log.error(e.getCode(),e); map.put("errorMsg", e.getCode()); } return map; }
以上這篇springMvc 前端用json的方式向后臺傳遞對象數組方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答