AspectJ 切面编程第二栏,关于注解使用
1:@Around 环绕通知
@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;
}
切入之后看下日志打印
如果不调用ProceedingJoinPoint的proceed方法,目标方法就被拦截了
@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;
}
2: @Before