JSR303 Composite Annotation

老子叫甜甜 提交于 2019-12-01 00:24:49

You could make use of @OverridesAnnotation:

@Digits(integer=0, fraction=0)
@Min(value=0)
@ReportAsSingleViolation
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target( { FIELD, METHOD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Constraint(validatedBy={})
public @interface PositiveInteger {
    String message() default "{positive.int.msg}";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};

    @OverridesAttribute(constraint=Digits.class, name="integer")
    int digits();
}

That way the value given in @PositiveInteger#digits() will be propagated to @Digits.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!