当前位置:网站首页>相同切入点的抽取
相同切入点的抽取
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之后......");
}
}
两者效果一致
边栏推荐
- Redis installation under windows and Linux systems
- Detailed explanation of four modes of distributed transaction (Seata)
- [combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
- do{}while()的妙用
- Calibre LVL
- 坚持输出需要不断学习
- Unity功能——Unity离线文档下载及使用
- “用Android复刻Apple产品UI”(3)—优雅的数据统计图表
- pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
- Break through 1million, sword finger 2million!
猜你喜欢

Microservice API gateway zuul

From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing

Unity function - unity offline document download and use

深度学习之三维重建

Create gradle project

Redis在Windows以及Linux系统下的安装
![App mobile terminal test [5] file writing and reading](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [5] file writing and reading

Uploads labs range (with source code analysis) (under update)

CString getbuffer and releasebuffer instructions

【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
随机推荐
VS2017通过IP调试驱动(双机调试)
C language brush questions ~leetcode and simple questions of niuke.com
【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
uploads-labs靶场(附源码分析)(更新中)
Driver and application communication
QT use qzxing to generate QR code
How to use AAB to APK and APK to AAB of Google play apps on the shelves
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
Unity功能——Unity离线文档下载及使用
[combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
From the 18th line to the first line, the new story of the network security industry
How can technology managers quickly improve leadership?
Please be prepared to lose your job at any time within 3 years?
Backtracking method to solve batch job scheduling problem
Use percent sign in CString
UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
Go语言自学系列 | golang switch语句
[combinatorics] combinatorial identity (sum of variable upper terms 1 combinatorial identity | summary of three combinatorial identity proof methods | proof of sum of variable upper terms 1 combinator
From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
工资3000,靠“视频剪辑”月入40000:会赚钱的人,从不靠拼命!