class A {
private String someField;
@validation
private String annotatedField;
}
我正在实施自定义约束验证注释@validation
以验证annotatedField
。我需要知道someField
的值,以满足我的验证逻辑。
Validator implements ConstraintValidator<validation, String>{
@Override
public void initialize(validation constraintAnnotation) {
}
@Override
public boolean isValid(String annotatedField, ConstraintValidatorContext context) {
if (StringUtils.isBlank(annotatedField)) {
return true;
}
String someField; // get some someField value given the annotatedField
}
}
有没有办法用反射做到这一点?