Spring快速入门之基于XML的AOP开发

学习目标:基于XML的AOP开发

一、切点表达式配置

  1. 切点表达式的写法:

在这里插入图片描述
常用第三个表达式
在这里插入图片描述

<aop:before method="before" pointcut="execution(* com.itheima.aop.*.*(..))"></aop:before>
<aop:after method="After" pointcut="execution(* com.itheima.aop.*.*(..))"></aop:after>
  1. 通知类型

在这里插入图片描述
具体实现:

  • 环绕通知
public Object Around(ProceedingJoinPoint pjp) throws Throwable {

    System.out.println("环绕前。。。。");
    //切点
   Object obj= pjp.proceed();
    System.out.println("环绕后。。。。");
    return obj;
}
//配置语句:
<aop:around method="Around" pointcut="execution(* com.itheima.aop.*.*(..))"></aop:around>
  • 异常抛出通知
通知类文件代码
public void afterThrowing(){
    System.out.println("异常抛出。。。");
}

//配置文件代码:
<aop:after-throwing method="afterThrowing" pointcut="execution(* com.itheima.aop.*.*(..))"></aop:after-throwing>

二、切点表达式的抽取

主要是提高代码的效率
具体代码如下:

在配置文件中修改

<!--        抽取切点表达式-->
<aop:pointcut id="myPcut" expression="execution(* com.itheima.aop.*.*(..))"/>

<aop:around method="Around" pointcut-ref="myPcut"></aop:around>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值