springMVC传递LIst

 

用下面的方式可以传递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<User> users;
 
    public List<User> getUsers() {
        return users;
    }
 
    public void setUsers(List<User> 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<EsbServiceV> ls;

	public List<EsbServiceV> getLs() {
		return ls;
	}

	public void setLs(List<EsbServiceV> ls) {
		this.ls = ls;
	}
	
	
}

 

@RequestMapping(value = "proxy/batchProxy.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> batchProxy(@RequestBody TempParameter temp){
		List<EsbServiceV> ls = temp.getLs();

	}

注意需要设置dataType 和contentType,否则连请求都不发。

 

 

 

springMVC 接收list参数问题 在线等

http://bbs.csdn.net/topics/380134180

 

SpringMVC list参数问题

http://www.iteye.com/problems/77789

 

SpringMVC绑定多个对象的集合

http://www.iteye.com/problems/38116

 

你可能感兴趣的:(springMVC)