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