springMvc 前端用json的方式向后台传递对象数组方法

网络编程 2021-07-04 16:46www.168986.cn编程入门
今天长沙网络推广就为大家分享一篇springMvc 前端用json的方式向后台传递对象数组方法,具有很好的参考价值,希望对大家有所帮助。一起跟随长沙网络推广过来看看吧

如下所示:

JSP
var Fee= new Array;
//遍历选中的对象

$("#feeList :checkbox:checked").each(function(i){
 Fee.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(Fee), 
 suess:function(data){ 
   //判断是否是成功的返回的
  if(data.suess===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> Fee){
  Map<String,Object> map=new HashMap<String,Object>();
  try {
   //判断对象是否为空
   if (Fee!=null&&Fee.size()>0) {
    //进行遍历并赋值
    for (VipFee v:Fee) {
     v.setReplacePrdId(Constants.PRODUCT_TYPE_FQB);
    }
   }
   //进行添加
   FeeService.addVipFeeList(Fee);
   map.put("suess", true);
  } catch (CoreException e) {
   map.put("suess", false);
   log.error(e.getCode(),e);
   map.put("errorMsg", e.getCode());
  }
  return map;
 }

以上这篇springMvc 前端用json的方式向后台传递对象数组方法就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by