由于某种原因,验证错误没有出现。事实上,绑定结果不会返回任何错误。我的豆子如下:
@NotBlank
@Size(min = 5, max = 20, message = "User ID must be 5 to 20 characters long.")
@Pattern(regexp = "^[a-zA-Z0-9]+$", message = "User ID must be alphanumeric.")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@NotBlank
@Size(min = 6, max = 20, message = "The password must be between 6 to 20 characters long.")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
我的控制器类具有以下变量:
private BeanValidator beanValidator = new BeanValidator(new AnnotationBeanValidationConfigurationLoader());
控制器中有一个处理绑定的方法。
beanValidator.validate(userLogin, bindingResult);
if(bindingResult.hasErrors()) {
return "/";
}
else
return "/homepage";
当我使用空白凭据登录用户名和密码值时,系统会登录。显然,bindingResult 没有检测到任何错误。帮助?