多層註解非必填處理

一、場景

當使用複合註解時,需要將多個註解包含到一個註解中時,註解字段是必填的,這時候需要處理

二、解決方法

複合註解

@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DataFilter {

    /**
     * 條件,取值自RxUserDetail.orgDetail.orgCode
     */
    Condition org() default @Condition(enabled = false);

    /**
     * 條件,取值自RxUserDetail.deptDetail.deptCode
     */
    Condition dept() default @Condition(enabled = false);

}

原子註解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Condition {
    /**
     * 是否開啓
     *
     * @return 默認開啓
     */
    boolean enabled() default true;

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章