获取方法和类上的注解信息

   获取方法上的注解,获取类上面的注解

   

  
//获取类所有的方法
Method[] methods = Test01Controller.class.getMethods(); for (int i=0;i<methods.length;i++){
//获取单个指定注解 Service annotation
= methods[i].getAnnotation(Service.class); System.out.println(annotation); } //获取所有注解 Annotation[] annotations = Test01Controller.class.getAnnotations(); for (int i=0;i<annotations.length;i++){ System.out.println(annotations[i]); }
原文地址:https://www.cnblogs.com/qq376324789/p/12217827.html