获取方法和类上的注解信息、判断是否有注解
获取方法上的注解,获取类上面的注解
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]); }