我在Controller里这样写的
@RequestMapping(value="/add",method=RequestMethod.POST)
public String addbinder(@Valid User user,BindingResult result) {
if(result.hasErrors()){
System.out.println("binder fail!");
return "ssuubb";
}else{
System.out.println("********************");
System.out.println(user.getNumber()+"here");
System.out.println(user.getAddress());
System.out.println(user.getPassword());
System.out.println("********************");
return "file";}
}
在实体bean中这样写的
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;
public class User{
@NotNull
private String number ;
@Size(max=20,min=10)
private String password ;
@NotEmpty
private String address ;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
System.out.println("user is ok");
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
让然郁闷的是我在表单提交空值执行后输出:
user is ok
********************
here
********************
就是说User是实体化了的,可空值验证不管用,页面还是跳转到了file.jsp 而不是ssuubb.jsp
那位帮忙看看啊
好像用错了吧,改用@NotNull试试