【发布时间】:2013-12-06 18:34:52
【问题描述】:
我正在尝试验证具有两个复合字段的 bean。这两个领域以 4 种不同的方式相互依赖。因此,我创建了 4 个不同的验证器(以重用)并将它们作为 bean 的类级别约束应用。它正在工作,但验证器没有按特定顺序被调用。我需要执行这个命令,因为验证器本身相互依赖。如果有其他更好的方法,请告诉我。
Spring-MVC、Spring 3.2.2、Hibernate 验证器 4.3.0.Final。
@ValidatorClassLevel
public class BeanClass{
@ValidatorProperty1
String property1;
String property2;
}
@ValidatorProperty2
@ValidatorProp1And2
@ValidatorProp1Or2
@Target( { TYPE, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = {Property12Validator.class})
@Documented
public @interface ValidatorClassLevel{
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
【问题讨论】:
标签: spring-mvc bean-validation hibernate-validator