当前位置:网站首页>相同切入点的抽取
相同切入点的抽取
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之后......");
}
}
两者效果一致
边栏推荐
- [proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
- [combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
- 阿飞的期望
- Three dimensional reconstruction of deep learning
- [200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
- 嵌入式开发:避免开源软件的7个理由
- Jmeter线程组功能介绍
- App mobile terminal test [3] ADB command
- Seckill system 2 redis solves the problem of distributed session
- 子类隐藏父类的同名函数
猜你喜欢

【Proteus仿真】74HC595+74LS154驱动显示16X16点阵

How are integer and floating-point types stored in memory

How can technology managers quickly improve leadership?

Intelij idea efficient skills (III)

WinDbg analysis dump file

"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation

近视:摘镜or配镜?这些问题必须先了解清楚

Embedded development: seven reasons to avoid open source software

半监督学习

String functions that you need to know
随机推荐
WinDbg分析dump文件
Project -- high concurrency memory pool
Approval process design
CString在多线程中的问题
C language brush questions ~leetcode and simple questions of niuke.com
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
[list to map] collectors Tomap syntax sharing (case practice)
首发!!lancet饿了么官方文档
Use percent sign in CString
Driver and application communication
Principles of several common IO models
Creation and destruction of function stack frames
Embedded development: seven reasons to avoid open source software
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
Custom annotation
秒殺系統3-商品列錶和商品詳情
Popular understanding of random forest
Problems of CString in multithreading
Jmeter线程组功能介绍
Detailed pointer advanced 2