我在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 {
}
请记住,这是自定义注释,因此您需要编写代码来处理它
PS 注意:假设您正在编写自定义注释。并在那里处理。