SomeClass.java
import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; public class SomeClass { @SomeToken public void someMethod() { } /* * 这个可以放在拦截器中 * */ public static void main(String[] args) throws SecurityException, NoSuchMethodException { Method method = SomeClass.class.getMethod("someMethod", new Class<?>[] {}); if (null != method && method.isAnnotationPresent(SomeToken.class)) { // 如果这个方法被这个注解类注解,则可以做一些特殊处理 System.out.println(11); } } } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface SomeToken { }
- Annotation JAVAannotation annotationformaterror java lang elementtype annotation 20230525 java annotation 20230707 java lang retentionpolicy annotation 20230707 java annotation repeatable 20230710 java retentionpolicy annotation 20230525 java annotation inherited 20230710 java springframework annotation程序java annotation java annotation