自己定义一个注解
1、定义类注解和方法注解 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface TypeAnnotation { String value() default "这是类注解"; } @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface MethodAnnotation { String value() default "这是方法注解"; } 2、处理注解 此处通过反射拿到类对象,获取注解,来操作。 再生产中也可以结合切面编程来处理注解,或者扫描指定包下的所有类,遍历处理注解 public class AnnotationHandler { public static void main(String[] args){ //可以配置扫描路径加载所有class,也可以使用aspectj直接做前面处理 Class aClass ....