日期:2014-05-17 浏览次数:20838 次
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;
public class User {
private int id;
private String name;
private int age;
private String address;
public User() {
}
public User(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@NotBlank(message = "请输入姓名")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Range(min = 0, max = 200, message = "请输入真实年龄")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@NotBlank(message = "请输入住址")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@ResponseBody
@RequestMapping(value = "action/add", method = RequestMethod.POST)
public Object addUser(@RequestBody @Validated User user/*, BindingResult bindingResult*/) {
/*if(bindingResult.hasErrors() {
return message;
*/
userService.saveUser(user);
return user;
}
public class BaseExceptionHandler implements HandlerExceptionResolver {
@Override
public ModelAndView resolveExceptio