Spring 基于Aspectj的注解开发AOP(三)-环绕通知@Around

 附:参考Spring 基于Aspectj的注解开发AOP(一)-前置通知

@Around 环绕通知

1、around方法的返回值就是目标代理方法执行返回值

2、参数为ProceedingJoinPoint 可以调用拦截目标方法的执行

目标方法:

 public void delete() {
        System.out.println("删除商品");
    }

 切面:环绕通知

@Around(value="execution(* com.lucifer.aspectj.demo.ProductDao.delete(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前通知======================");
        Object obj=joinPoint.proceed();//执行目标方法
        System.out.println("环绕后通知======================");
        return obj;
    }

Spring 基于Aspectj的注解开发AOP(三)-环绕通知@Around

ps:如果不调用ProceedingJoinPoint的proceed方法,目标方法就被拦截了;如图:

Spring 基于Aspectj的注解开发AOP(三)-环绕通知@Around