controller 方法中用
@RequestBody List<Bean> list 参数接收机和类型数据
前台如果是ajax提交
使用 JSON.stringify(list) 格式化下数组
请求头设置 contentType : 'application/json;charset=utf-8'
例子
var customerArray = new Array();
customerArray.push({id: "1", name: "李四", pwd: "123"});
customerArray.push({id: "2", name: "张三", pwd: "332"});
$.ajax({
url: "xx",
type: "POST",
contentType : 'application/json;charset=utf-8', //设置请求头信息
dataType:"json",
data: JSON.stringify(customerArray),
success: function(data){
},
error: function(res){
alert(res.responseText);
}
});
@RequestMapping(value = "/xx", method ={RequestMethod.POST})
@ResponseBody
public String method1(@RequestBody List<User> users)
throws Exception{
System.out.println(users);
return null;
}