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) {  
        ...
    }
    
  • 相关阅读:
    AdminLTE模板
    日历插件
    Jquery 拖拽表格宽度
    Java桌面程序打包成exe可执行文件
    使用Access-Control-Allow-Origin解决跨域
    Ubuntu默认root密码
    Lua的require和module小结
    nginx 安装
    chkconfig命令
    [转]fedora启动telnet服务
  • 原文地址:https://www.cnblogs.com/zpKang/p/15153320.html
Copyright © 2011-2022 走看看