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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

ITBOY_ITBOX   2021-03-31 我要评论

如下所示:

JSP
var 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的方式向后台传递对象数组方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们