zoukankan      html  css  js  c++  java
  • AOP简单读取注解等内容

    自定义注解

    @Target({ElementType.PARAMETER, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface OperationLog {
        String description() default "";
    }
    

    aop类

    @Aspect
    @Component
    public class WebOperationRecordHandle {
        
        @Pointcut("@annotation(com.test.aspect.OperationLog)")
        public void operationAspect() {
            
        }
    
        /*
        * 将被加强类的注解传入方法参数
        */
        @Before(value = "operationAspect() && @annotation(operationLog)", argNames = "operationLog")
        public void beforeHandel(OperationLog operationLog) {
            String description = operationLog.description();
            System.out.println(description);
        }
    

    被加强的类

        @OperationLog(description = "测试方法")
        public Json test() {
    
        }
    

    以下为获取被加强方法其他内容的写法

    @Around(value = "args(param) && target(bean) && @annotation(logAnnotation)", argNames = "jp, param, bean, logAnnotation")
    public void before(JoinPoint jp, String param, PersonService bean, LogAnnotation logAnnotation) {  
        ...
    }
    
  • 相关阅读:
    Java入门——day42
    第六周进度报告
    Java入门——day41
    Java入门——day40
    Java入门——day39
    Java入门——day38
    Java入门——day37
    Java入门——day36
    Java入门——day35
    第五周进度报告
  • 原文地址:https://www.cnblogs.com/zpKang/p/15153320.html
Copyright © 2011-2022 走看看