首页 文章

Spring JSR 303验证组被忽略

提问于
浏览
0

我们有一个带有JSR注释的简单bean

public class CustomerDTO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @NotEmpty(message = "{customer.firstname.empty}")
    private String firstName;

    @NotEmpty(message = "{customer.lastname.empty}")
    private String lastName;

    @NotEmpty(groups={PasswordChange.class}, message="{password.empty}")
    private String password;

    @NotEmpty(groups={PasswordChange.class}, message="{confirmation.password.empty}")
    private String password2;

}

我们有一个Spring Controller

@RequestMapping(value="/changePassword", method = RequestMethod.POST)
public String changePassword(@Validated({ PasswordChange.class }) @ModelAttribute("customerdto") CustomerDTO customerDTO, BindingResult result, Locale locale) {
    logger.debug("Change Password was submitted with information: " + customerDTO.toString());
    try {
        passwordStrengthPolicy.checkPasswordStrength(locale, customerDTO.getPassword());
        if (result.hasErrors()) {
            return "changePassword";
        }
        logger.debug("Calling customer service changePassword: " + customerDTO);
        customerOnlineNewService.changePassword(customerDTO);
    } catch (PasswordNotChangedException e) {
        logger.error("Could not change password PasswordNotChangedException: " + customerDTO.toString());
            return "changePassword";
    } catch (PasswordNotSecureException e) {
        return "changePassword";
    }
    return createRedirectViewPath("changePassword");
}

我们的问题是,当调用changePassword时,验证器会忽略该组(PasswordChange.class)并仅验证不在该组中的firstName和lastName .

任何的想法?非常感谢您的宝贵时间 .

1 回答

相关问题