【问题标题】:how to specify validator order with respect to cross field validation如何针对跨字段验证指定验证器顺序
【发布时间】: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


    【解决方案1】:

    您可以使用验证 group sequences 来强制执行特定顺序的约束。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-24
      • 2014-11-05
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多