SpringMVC @RequestBody 接收Json数组对象

<script type="text/javascript">  
    $(document).ready(function(){  
     $.ajax({
         type:'POST',
         url:'<%=path%>/user/ceshi.do',
	 dataType:"json",      
	 contentType:"application/json",   
	 data:JSON.stringify([{id:"1",name:"cehshi1"},{id:"2",name:"ceshi2"}]),
         success:function(){			
	 }
    });
</script>

  

@RequestMapping(value = "/ceshi", method = {RequestMethod.POST }) 
@ResponseBody
public void ceshi(@RequestBody User[] users){
	for (User user : users) {
	System.out.println(user.getId());
	}
}
注: 后台用对象数组接收User[] users  不要用List<T>  list只支持简单属性类型   

(@RequestBody List<int> ids) ==> [360,361,362] )

  

posted @ 2019-12-26 16:50  关键步就几步  阅读(1656)  评论(0编辑  收藏  举报