一、JoinPoint核心方法
1.JoinPoint核心方法表
| 注解 | 说明 |
|---|
| Object getTarget() | 获取IOC容器内目标对象【获取目标类的名称】 |
| Signature getSignature() | 获取目标方法【获取目标方法名称】 |
| Object[] getArgs() | 获取目标方法参数【获取参数】 |
2.代码示例
package com.learn.spring.aop.aspect;
import org.aspectj.lang.JoinPoint;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MethodAspect {
public void printExecutionTime(JoinPoint joinPoint){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
String now = sdf.format(new Date());
String className = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
System.out.println("------>" + now + ":" + className + "." + methodName);
Object[] args = joinPoint.getArgs();
System.out.println("----->参数个数:" + args.length);
for (Object arg : args){
System.out.println("----->参数:" + arg);
}
}
}