我如何执行 ConstraintValidatorConstraintValidator?

我有一个习俗 @NotEmpty 并有习惯 ConstraintValidator对于每种类型,它都可以正常工作。

现在,我想创建一个级别的约束,该约束至少检查指定字段中的一个并不使用这些自定义 ConstraintValidator我已经有。约束部分(@ClassNotEmpty),但是问题是 ConstraintValidator 执行。我如何获得 ConstraintValidator 给定约束的实例? IE

isValid(Object value, ConstraintValidatorContext constraintValidatorContext)  {
    String[] fieldValues = getFieldValues(value, this.classNotEmpty.fieldNames());

    for (String fieldValue : fieldValues) {
        <What do I put here?>.isValid(fieldValue, constraintValidatorContext);
    }
}

有没有办法这样做,而无需将验证例程提升到帮手课程?

顺便说一句,我正在使用弹簧和休眠验证器。

有帮助吗?

解决方案

经过进一步的研究,看来没有已知的解决方案来获得 ConstraintValidator 给定约束,可移植与否的实例。帮手课程似乎是唯一做到这一点的方法。

其他提示

我没有在我面前的信息,但是我记得读过有关其他验证者组成的有关验证者的信息。因此,如果您有两个验证器A和B。您可以定义由其他两个组成的第三个“ C”。通过DOCO狩猎,您应该找到它。

只是进行了搜索,请阅读以下内容: http://docs.jboss.org/hibernate/stable/validator/Reference/en-us/html/validator-customconstraints.html#validator-customconstomcontaints-compounds-compounds

这可能是您想要的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top