用下面的方式可以传递List形式的参数,达到我的目的,看到spring3.0的文档,接受参数的确没有List形式的,不知大家还有什么更好的方法?
$.ajax({
type: 'POST',
url: '',
data: JSON.stringify({"users":[{name:"Tom",age:12},{name:"Petter",age:14}]}), // 必须转成String
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(data){
}
});
@ResponseBody
@RequestMapping("/test")
public Object test(@RequestBody Temp temp)
{
return new Object();
}
public class Temp
{
private List users;
public List getUsers() {
return users;
}
public void setUsers(List users) {
this.users = users;
}
}
public class User
{
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
自己的:
var datasArr = $('#tab_batch').datagrid("getRows");
var datas = {};
datas.ls = datasArr;
var para = JSON.stringify(datas);
$.ajax({
type: 'POST',
url: root + 'proxy/batchProxy.do',
data: para, // 必须转成String
dataType: 'json',
timeout: 180000,
contentType: "application/json; charset=utf-8",
success: function(data){
$.messager.progress("close");
afterProxy(data);
},
error: function(data){
$.messager.progress("close");
afterProxy(data);
}
});
public class TempParameter {
private List ls;
public List getLs() {
return ls;
}
public void setLs(List ls) {
this.ls = ls;
}
}
@RequestMapping(value = "proxy/batchProxy.do", method = RequestMethod.POST)
@ResponseBody
public Map batchProxy(@RequestBody TempParameter temp){
List ls = temp.getLs();
}
注意需要设置dataType 和contentType,否则连请求都不发。
springMVC 接收list参数问题 在线等
SpringMVC list参数问题
SpringMVC绑定多个对象的集合