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

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;
    }


  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值