一、場景
當使用複合註解時,需要將多個註解包含到一個註解中時,註解字段是必填的,這時候需要處理
二、解決方法
複合註解
@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;
}