获取方法和类上的注解信息、判断是否有注解


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

   

if(f.isAnnotationPresent(ApiModelProperty.class)){

 

  
//获取类所有的方法
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]); }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM