JSR303 Composite Annotation

前端 未结 1 1357
长发绾君心
长发绾君心 2021-01-06 06:16

I\'ve created a composite annotation that consists of @Digits and @Min

@Digits(integer=12, fraction=0)
@Min(value=0)
@ReportAsSingleViolation
@Documented
@Re         


        
相关标签:
1条回答
  • 2021-01-06 06:28

    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.

    0 讨论(0)
提交回复
热议问题