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) {  
        ...
    }
    
  • 相关阅读:
    第22章 算法
    第二十一章 数据结构
    mysql 索引
    MySQL 视图
    MySQL 子查询
    MySQL 批量更新数据
    MySQL 默认值
    Spring 整体架构和环境搭建
    python之字符串
    python学习
  • 原文地址:https://www.cnblogs.com/zpKang/p/15153320.html
Copyright © 2011-2022 走看看