I have a model class
public class Account {
@Email
private String email;
@NotNull
private String rule;
}
and spring-validator
public class AccountValidator implements Validator {
@Override
public boolean supports(Class aClass) {
return Account.class.equals(aClass);
}
@Override
public void validate(Object obj, Errors errors) {
Account account = (Account) obj;
ValidationUtils.rejectIfEmpty(errors, "email", "email.required");
ValidationUtils.rejectIfEmpty(errors, "rule", "rule.required");
complexValidateRule(account.getRule(), errors);
}
private void complexValidateRule(String rule, Errors errors) {
}
}
I start my service
AccountValidator validator = new AccountValidator();
Errors errors = new BeanPropertyBindingResult(account, "account");
validator.validate(account, errors);
Can I add @Email, @NotNull (JSR-303) verification procedures to my restrictions and not describe these rules in AccountValidator?
I know how @Valid works in spring controllers, but what about the service level? Is it possible? How to conduct such a check? Can I use the Hibernate Validator?
source
share