ProceedingJoinPoint 获取参数方法名
时间: 2024-02-22 07:53:05 浏览: 33
ProceedingJoinPoint是AspectJ框架中的一个接口,用于获取当前方法和参数的信息。通过使用ProceedingJoinPoint对象,可以获取方法名和参数。
以下是一个示例代码,演示如何使用ProceedingJoinPoint获取方法名和参数:
```java
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class MyAspect {
@Around("execution(* com.example.MyClass.myMethod(..))")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
String methodName = joinPoint.getSignature().getName(); // 获取方法名
Object[] args = joinPoint.getArgs(); // 获取参数
System.out.println("方法名:" + methodName);
System.out.println("参数:" + args[0]);
return joinPoint.proceed();
}
}
```
在上述代码中,我们使用@Around注解将around方法绑定到目标方法上。在around方法中,我们通过joinPoint.getSignature().getName()获取方法名,通过joinPoint.getArgs()获取参数。
请注意,上述代码中的execution(* com.example.MyClass.myMethod(..))是一个切入点表达式,用于指定目标方法。你需要根据实际情况修改该表达式。