ProceedingJoinPoint详解
AI-摘要
CaiCai GPT
AI初始化中...
介绍自己
生成本文简介
推荐相关文章
前往主页
前往tianli博客
本文最后更新于 2024-07-01,文章内容可能已经过时。
源码
package org.aspectj.lang;
import org.aspectj.runtime.internal.AroundClosure;
public interface ProceedingJoinPoint extends JoinPoint {
void set$AroundClosure(AroundClosure var1);
default void stack$AroundClosure(AroundClosure arc) {
throw new UnsupportedOperationException();
}
Object proceed() throws Throwable;
Object proceed(Object[] var1) throws Throwable;
}
//joinpoint实现:
public Object proceed() throws Throwable {
if (this.arcs == null) {
return this.arc == null ? null : this.arc.run(this.arc.getState());
} else {
return ((AroundClosure)this.arcs.peek()).run(((AroundClosure)this.arcs.peek()).getState());
}
}
Proceedingjoinpoint 继承了JoinPoint,在JoinPoint的基础上暴露出 proceed(), 这个方法是AOP代理链执行的方法。ProceedingJoinPoint包含了被通知方法的执行信息,同时可以访问被通知方法的信息和参数。可以通过使用ProceedingJoinPoint接口来实现更加灵活和精细的环绕通知逻辑。
用法
获得切点对应的方法(Method)
@Around("pointCut()")
public void around3(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
}
获得参数(Object[])
@Around("pointCut()")
public void around3(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] objects = joinPoint.getArgs();
for (Object o : objects) {
System.out.println(o);
if (o instanceof User) {
System.out.println("id是:" + ((User) o).getId() +
"; 名字是:" + ((User) o).getUserName() +
"; 备注是:" + ((User) o).getNote());
}
}
}
获得目标类
@Around("pointCut()")
public void around3(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("joinPoint.getTarget().toString() : " +
joinPoint.getTarget().toString());
}
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 caicaiBlog
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果