如何把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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM