本文介绍了有没有办法从Bean Validation字段级ConstraintValidator中访问目标bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了使用类级验证之外,有没有办法从验证器类中访问字段级验证注释的父bean?
Apart from using class-level validations, is there a way to access the parent bean of a field-level validation annotation from within its validator class?
例如:
public class CustomValidator implements ConstraintValidator<CustomValidation, String> {
@Override
public void initialize(final CustomValidation constraintAnnotation) {
}
@Override
public boolean isValid(final String fieldValue, final ConstraintValidatorContext context) {
// is there a way to access the parent object here?
}
}
推荐答案
进一步的调查,事实证明这对于规范1.1版是不可能的。
Upon further investigation, it turns out this is not possible with the version 1.1 of the spec.
这篇关于有没有办法从Bean Validation字段级ConstraintValidator中访问目标bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!