当前位置:网站首页>相同切入点的抽取
相同切入点的抽取
2022-07-03 16:01:00 【不入开发不工作】
1.相同切入点的抽取
抽取前:
package com.spring.spring5.annotaion;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//增强的类
@Aspect//表示生成代理对象
@Component
public class UserProxy {
//前置通知
@Before(value = "execution(* com.spring.spring5.annotaion.User.add(..))")//表示作为前置通知
public void before(){
System.out.println("Before......");
}
//最终通知,不管有没有异常在方法之后都执行
@After(value = "execution(* com.spring.spring5.annotaion.User.add(..))")
public void after(){
System.out.println("After......");
}
//后置通知(返回通知),方法无异常结束时执行
@AfterReturning(value = "execution(* com.spring.spring5.annotaion.User.add(..))")
public void afterReturning(){
System.out.println("AfterReturning......");
}
//异常通知,add()有异常时才会执行
@AfterThrowing(value = "execution(* com.spring.spring5.annotaion.User.add(..))")
public void afterThrowing(){
System.out.println("AfterThrowing......");
}
//环绕通知,在方法之前和之后执行
@Around("execution(* com.spring.spring5.annotaion.User.add(..))")
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("Around之前......");
proceedingJoinPoint.proceed();
System.out.println("Around之后......");
}
}
抽取后:
package com.spring.spring5.annotaion;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//增强的类
@Aspect//表示生成代理对象
@Component
public class UserProxy {
//相同切入点抽取
@Pointcut("execution(* com.spring.spring5.annotaion.User.add(..))")
public void pointdemo() {
}
//前置通知
@Before(value = "pointdemo()")//表示作为前置通知
public void before(){
System.out.println("Before......");
}
//最终通知,不管有没有异常在方法之后都执行
@After(value = "pointdemo()")
public void after(){
System.out.println("After......");
}
//后置通知(返回通知),方法无异常结束时执行
@AfterReturning(value = "pointdemo()")
public void afterReturning(){
System.out.println("AfterReturning......");
}
//异常通知,add()有异常时才会执行
@AfterThrowing(value = "pointdemo()")
public void afterThrowing(){
System.out.println("AfterThrowing......");
}
//环绕通知,在方法之前和之后执行
@Around("pointdemo()")
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("Around之前......");
proceedingJoinPoint.proceed();
System.out.println("Around之后......");
}
}
两者效果一致
边栏推荐
- Detailed explanation of string function and string function with unlimited length
- The difference between calling by value and simulating calling by reference
- Semi supervised learning
- CString getbuffer and releasebuffer instructions
- Automatic generation of client code from flask server code -- Introduction to flask native stubs Library
- [200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
- Go language self-study series | golang switch statement
- Low level version of drawing interface (explain each step in detail)
- App移动端测试【3】ADB命令
- Redis在Windows以及Linux系统下的安装
猜你喜欢
Popular understanding of random forest
App mobile terminal test [4] APK operation
Semi supervised learning
Microservice API gateway
From the 18th line to the first line, the new story of the network security industry
Microservice - declarative interface call openfeign
Low level version of drawing interface (explain each step in detail)
Unity功能——Unity离线文档下载及使用
半监督学习
[list to map] collectors Tomap syntax sharing (case practice)
随机推荐
App移动端测试【5】文件的写入、读取
Detailed pointer advanced 2
[list to map] collectors Tomap syntax sharing (case practice)
Seckill system 3- product list and product details
VC下Unicode和ANSI互转,CStringW和std::string互转
Three dimensional reconstruction of deep learning
Second kill system 3 - list of items and item details
用通达信炒股开户安全吗?
使用AUR下载并安装常用程序
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
Automatic generation of client code from flask server code -- Introduction to flask native stubs Library
UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
How can technology managers quickly improve leadership?
秒殺系統3-商品列錶和商品詳情
突破100万,剑指200万!
MB10M-ASEMI整流桥MB10M
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Backtracking method to solve batch job scheduling problem
Use percent sign in CString
pycharm错Error updating package list: connect timed out