如何把List集合从前台传到后台?后台怎么接收?-sunziren

  1. 前台定义数组。

    var dataList = [];

  2. 前台循环往数组里面push,每一次循环就相当于push了一个对象。

    dataList.push({age:18,name:‘张三’,hobby:‘弹琴’});

  3. 前台把这个数组转化为json格式的字符串,并放到ajax中传送到后台。

    $.ajax({

      url:'commonController/savePeople',

      type:'get',

      data:{peopleStr:Json.stringify(dataList)},

      dataType:'json',

      success:function(data){

      }

    })

  4. 后台接受这个字符串,然后用下面的方法转为LIst对象数组。

    import com.alibaba.fastjson.JSON

    List<People> peopleList = JSON.parseArray(peopleStr,People.Class);

原文地址:https://www.cnblogs.com/sunziren/p/14273304.html