用例:在添加/编辑地址或设置直接递送地址时,表单具有相同的字段。因此,最好将地址表单类用作交付表单的超类:
public class AddressForm {
@NotEmpty
private String name;
// ...
}
public class DeliveryForm extends AddressForm {
public static enum ShippingType {
DIRECT_SHIPPING,
// ...
}
@NotNull
private ShippingType shippingType;
// ...
}
是否可以在类级别创建自定义约束(验证器)来设置是否应验证超类的条件?
如:
@ValidateSuperclassIf(field = "shippingType", value = "DIRECT_SHIPPING")
public class DeliveryForm extends AddressForm {
// ...
}
如何实施javax.validation.ConstraintValidator<ValidateSuperclassIf, Object>.isValid(Object value, ConstraintValidatorContext context)
方法?