JSR アノテーションを持つ単純な Bean があります
パブリック クラス CustomerDTO {
private static final long serialVersionUID = 1L;
プライベート整数 ID;
@NotEmpty(message = "{customer.firstname.empty}")
プライベート文字列 firstName;
@NotEmpty(message = "{customer.lastname.empty}")
プライベート文字列 lastName;
@NotEmpty(groups={PasswordChange.class}, message="{password.empty}")
プライベート文字列パスワード;
@NotEmpty(groups={PasswordChange.class}, message="{confirmation.password.empty}")
プライベート文字列 password2;
}
そしてSpring Controllerがあります
@RequestMapping(value="/changePassword", メソッド = RequestMethod.POST)
public String changePassword(@Validated({ PasswordChange.class }) @ModelAttribute("customerdto") CustomerDTO customerDTO, BindingResult result, Locale locale) {
logger.debug("パスワードの変更が次の情報とともに送信されました: " + customerDTO.toString());
試す {
passwordStrengthPolicy.checkPasswordStrength(ロケール, customerDTO.getPassword());
if (result.hasErrors()) {
"changePassword" を返します。
}
logger.debug("顧客サービスの呼び出し changePassword: " + customerDTO);
customerOnlineNewService.changePassword(customerDTO);
} キャッチ (PasswordNotChangedException e) {
logger.error("パスワードを変更できませんでした PasswordNotChangedException: " + customerDTO.toString());
"changePassword" を返します。
} キャッチ (PasswordNotSecureException e) {
"changePassword" を返します。
}
return createRedirectViewPath("changePassword");
}
私たちの問題は、changePassword が呼び出されると、バリデーターがグループ (PasswordChange.class) を無視し、グループにない firstName と lastName のみを検証することです。
何か案が?どうぞよろしくお願いいたします。