我对 getter 有几个注释,如下所示。我想跳过基于同一个类中的布尔值的 getter 上的所有注释调用。有什么办法可以做到吗?

@MyAnnotation1(message = "{someMessage1}")
@MyAnnotation2(message = "{someMessage2}")
public Date getFromDate() {
    return fromDate;
}
有帮助吗?

解决方案

您可以将另一个注释定义为 @Ignore 在该字段上,如果设置了注释字段,您可以简单地忽略注释处理。

   @Ignore
   private boolean value;

您可以将自己的注释定义为

   @Target(ElementType.FIELD)
   @Retention(RetentionPolicy.RUNTIME)
   /**
    * This Annotation should be used on boolean field to set specify whether annotation processing should be        ignored for that class
    */
   public @interface Ignore {

   }

请记住这是自定义注释,因此您需要编写代码来处理它

注:假设您正在编写自定义注释。并有加工。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top