spring-mvc List及数组的配置接收

数组接收

 

前台传递数组id

后台接收方式:

public WebReturnObject deleteBatch(@RequestParam("id[]") String[] ids, HttpServletRequest request)
public WebReturnObject deleteBatch(@RequestParam("id[]") List<String> ids, HttpServletRequest request)

 

复杂对象集合接收

前台传递复杂对象的json格式

$.ajax(
                {
                  url:url, 
                  type: "POST", 
                  data: JSON.stringify(x), 
                  success: function(data){
                      
                  }, 
                  dataType: "json",
                  contentType: "application/json"
               } );

 

后台用对象接收

public class User{
  private List<Home> homes;  
  
  ...

}


public class Home{
  private String address;
  private String father;
  
  ...

}

public class Controller{
    public void save(@RequestBody User user);

 注:接收复杂对象需要添加@RequestBody,否则会报500错误

posted @ 2016-09-20 16:34  Mr.Ming2  阅读(1530)  评论(0编辑  收藏  举报