美文网首页
SpringBoot(29) — AOP编程之环绕通知@Arou

SpringBoot(29) — AOP编程之环绕通知@Arou

作者: 奔跑的佩恩 | 来源:发表于2021-09-03 11:01 被阅读0次

前言

在上一节中,我们已经讲到了AopSpringBoot中的使用,大家有兴趣的话,可参考以下文章
SpringBoot(28) — AOP切面编程
然后在Aop的切面变成中,我们有很多涉及到流程的注解,如@Before@After等。在这些流程注解中有一个功能最为强大的通知,这就是环绕通知@Around

今天涉及的内容有:

  1. @Around 的强大之处
  2. @Around 的使用
  3. @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:

相关文章

网友评论

      本文标题:SpringBoot(29) — AOP编程之环绕通知@Arou

      本文链接:https://www.haomeiwen.com/subject/xmnhwltx.html