`

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只支持简单属性类型   

 

分享到:
评论
4 楼 song126 2016-10-19  
感谢博主
3 楼 windersehen 2015-09-02  
感谢博主,解决了我的问题
2 楼 haolianshuai 2013-11-13  
牛人,赞一个!
1 楼 lib 2013-11-13  
沙发。

相关推荐

Global site tag (gtag.js) - Google Analytics