前台:functionpost4(){varpara={'user.username':"name",'user.password':"password"};$.ajax({url:'vote/post4.html',data:para,success:function(data){alert(data);}});}后台:@RequestMapping(value="/post4")publicvoidpost4(@ModelAttribute("user")Useruser,PrintWriterout){System.out.println(user.getPassword());out.write(user.getUsername());out.flush();out.close();}可是我这么写报空啊,要加什么别的,或者架包么更精细的匹配你可以实现一个springmvc的WebArgumentResolver接口,然后配在的子标签里:)
@RequestMapping(value="/test",method=RequestMethod.POST)
public @ResponseBody Map
@RequestBody UserForm userForm,
BindingResult bindingResult) {
Map
if (bindingResult.hasErrors()) {
map.put("errorCode", "40001");
map.put("errorMsg", bindingResult.getFieldError().getDefaultMessage());
}
map.put("user", userForm);
return map;
}