我们有一个带有 JSR 注释的简单 bean
公共类 CustomerDTO {
私有静态最终长序列版本UID = 1L;
私人整数 id;
@NotEmpty(message = "{customer.firstname.empty}")
私人字符串名;
@NotEmpty(message = "{customer.lastname.empty}")
私人字符串姓氏;
@NotEmpty(groups={PasswordChange.class}, message="{password.empty}")
私人字符串密码;
@NotEmpty(groups={PasswordChange.class}, message="{confirmation.password.empty}")
私人字符串密码2;
}
我们有一个 Spring Controller
@RequestMapping(value="/changePassword", 方法 = RequestMethod.POST)
public String changePassword(@Validated({ PasswordChange.class }) @ModelAttribute("customerdto") CustomerDTO customerDTO, BindingResult 结果, Locale locale) {
logger.debug("更改密码已提交信息:" + customerDTO.toString());
尝试 {
passwordStrengthPolicy.checkPasswordStrength(locale, customerDTO.getPassword());
if (result.hasErrors()) {
返回“更改密码”;
}
logger.debug("调用客服更改密码:" + customerDTO);
customerOnlineNewService.changePassword(customerDTO);
} 捕捉(PasswordNotChangedException e){
logger.error("无法更改密码 PasswordNotChangedException:" + customerDTO.toString());
返回“更改密码”;
} 捕捉(PasswordNotSecureException e){
返回“更改密码”;
}
return createRedirectViewPath("changePassword");
}
我们的问题是,当调用 changePassword 时,验证器会忽略组(PasswordChange.class)并仅验证不在组中的 firstName 和 lastName。
任何想法?非常感谢您的宝贵时间。