@Around 返回值
来源:3-4 环绕通知
饭勺超人
2019-10-04 14:40:33
@Around(value = "execution(public * com.wenqiang.aspectj.demo1.ProductDao.update (..))") public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { System.out.println("环绕前通知"); Object o =proceedingJoinPoint.proceed(); System.out.println("环绕后通知"); return o; // return null; } @Test public void demo1(){ // productDao.delete(); // productDao.finaAll(); // productDao.findOne(); // productDao.save(); productDao.update(); }
around 方法中,return o, retuen null的执行结果都是一样的,那around方法中的return 作用是什么?
输出结果最后那串代表的是什么意思
另外,阻止目标方法执行时:
@Around(value = "execution(public * com.wenqiang.aspectj.demo1.ProductDao.update (..))") public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { System.out.println("环绕前通知"); // Object o =proceedingJoinPoint.proceed(); System.out.println("环绕后通知"); return null; }
写么?谢谢老师
1回答
好帮手慕柯南
2019-10-06
同学你好!
同学这里无论返回什么,最终的结果都是一样的原因是:被增强的类本身没有返回值,或者同学没有打印输出返回值。当有返回值时如果返回null最终的结果会返回null,比如:
阻止目标方法执行,同学的想法时正确的。
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
相似问题