当前位置: 移动技术网 > IT编程>开发语言>JavaScript > springMvc 前端用json的方式向后台传递对象数组方法

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

2018年08月19日  | 移动技术网IT编程  | 我要评论
如下所示: jsp var vipfee= new array; //遍历选中的对象 $("#feelist :checkbox:checked").e

如下所示:

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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网