zoukankan      html  css  js  c++  java
  • 注解方式声明切面

    @aspect:用于指定一个类为切面类;
    @Pointcut:声明一个切入点,指定切面用在那些类的那些方法上;
    @Before、@AfterReturning、@After、@AfterThrowing、@Around:指定advice何时执行切面;
    具体运用如下:
    @Aspect
    public class MyInterceptor {
        @Pointcut("execution (* cn.itcast.service.impl.PersonServiceBean.*(..))")
        private void anyMethod() {}//声明一个切入点
        
        @Before("anyMethod() && args(name)")
        public void doAccessCheck(String name) {
            System.out.println("前置通知:"+ name);
        }
        @AfterReturning(pointcut="anyMethod()",returning="result")
        public void doAfterReturning(String result) {
            System.out.println("后置通知:"+ result);
        }
        @After("anyMethod()")
        public void doAfter() {
            System.out.println("最终通知");
        }
        @AfterThrowing(pointcut="anyMethod()",throwing="e")
        public void doAfterThrowing(Exception e) {
            System.out.println("例外通知:"+ e);
        }
        
        @Around("anyMethod()")
        public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
            //if(){//判断用户是否在权限
            System.out.println("进入方法");
            Object result = pjp.proceed();
            System.out.println("退出方法");
            //}
            return result;
        }
        
    }

  • 相关阅读:
    空心杯 电机
    scikit learn 安装
    python fromkeys() 创建字典
    python 清空列表
    mac最常用快捷键
    php while循环
    php 获取某个日期n天之后的日期
    php 添加时间戳
    php 格式化时间
    php 数值数组遍历
  • 原文地址:https://www.cnblogs.com/liwendeboke/p/6231830.html
Copyright © 2011-2022 走看看