点击查看代码
数组名+[]的方式,可以传递数组,表单中所有的数组项可以用相同的name,serializeJSON会识别他们并放到一个数组里。
<input type="text" name="employees[]"/>
接收时,可以在bean中使用 private String[] employees; 进行接收。
$.ajax({
type: 'POST',
url: '。。。',
data: $('#form').serializeJSON(),
success: function (json) {
}
});
对象数组可以用<input type="text" name="employees[][id]"/>
接收时,可以在bean中使用 private Employee[] employees; 进行接收。
后台接收还有两种方式
<input name="idList" /><input name="idList" />
public ResponseTemplate deleteUser(@RequestParam("idList") List<Long> idList) {
...
}
json数组 :[{id:1,name:a},{id:2,name:b}]
public ResponseTemplate updatePositionPriority(@RequestBody List<Position> positions) {
...
}