spring中自定义注解(annotation)与获取注解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qpfjalzm123/article/details/45061677

注解类自定义

package me.lichunlong.spring.annotation;


import java.lang.annotation.Documented;   
import java.lang.annotation.ElementType;   
import java.lang.annotation.Retention;   
import java.lang.annotation.RetentionPolicy;   
import java.lang.annotation.Target;   

@Target({ElementType.METHOD})   
@Retention(RetentionPolicy.RUNTIME)   
@Documented

public @interface LogAnnotation {   
    String desc() default "无描述信息";   

}  


获取方法及所在类上的某个注解

public static Object[] findAnnotation(Method method, Class annotationClass){
    Object methodAnnotation = method.getAnnotation(annotationClass);
    Object classAnnotation = method.getDeclaringClass().getAnnotation(annotationClass);
    Object[] result = {classAnnotation, methodAnnotation};
    return result;
}


展开阅读全文

没有更多推荐了,返回首页