Eneity:
public class User{
private String name;
private String pwd;
//省略get/set
}
前台JavaScript:
funciton fangfa(){ var list = new Array(); list.put({name:"zhangsan",pwd:"123123"}); list.put({name:"lisi",pwd:"1231233"}); $.ajax({ type: "POST", url: "/baocunlist", data: JSON.stringify(list),//将对象序列化成JSON字符串 dataType:"json", contentType : 'application/json;charset=utf-8', //设置请求头信息 success: function(data){ alert(data); } }); }
后台打印代码:
@RequestMapping("baocunlist")
@ResponseBody
public String baocunlist(@RequestBody List list,HttpServletRequest request,Model model,RedirectAttributes redirectAttributes) {
for (User user : list) {
System.out.println(user.getName());
}
}