前言
在上一节中,我们已经讲到了Aop
在SpringBoot
中的使用,大家有兴趣的话,可参考以下文章
SpringBoot(28) — AOP切面编程
然后在Aop
的切面变成中,我们有很多涉及到流程的注解,如@Before
,@After
等。在这些流程注解中有一个功能最为强大的通知,这就是环绕通知@Around
。
今天涉及的内容有:
- @Around 的强大之处
- @Around 的使用
- @Around使用总结
一. @Around 的强大之处
@Around
是一个强大的通知。一般使用它时,是你在需要大幅度修改原有目标对象的业务逻辑时才用到,否则都是用其他的通知。环绕通知可以取代原有目标对象方法的通知,也具备回调原有目标对象方法的能力。
二. @Around 的使用
这里我们还是简单的介绍下。切面导入依赖什么的,大家可参考
SpringBoot(28) — AOP切面编程
然后先是给出切点入口类Iprinter
:
/**
* Title:
* description:
* autor:pei
* created on 2019/9/3
*/
public interface Iprinter {
void printInfo(String message,int code);
}
其实现类Printer
:
@Component("Printer")
public class Printer implements Iprinter {
@Override
public void printInfo(String message, int code) {
if (StringUtil.isEmpty(message)) {
throw new NullPointerException("====参数不能为空====");
}
LogUtil.println("======我是要打印的信息啊: " + message);
}
}
接着我们写一个切面类CustomAspect
:
网友评论