1)JoinPoint
Object[] getArgs():获取连接点方法运行时的传入参列表;
Signature getSignature() :获取连接点的方法对象;
Object getTarget() :获取连接点所在的目标对象;
Object getThis() :获取代理对象本身;
2)ProceedingJoinPoint
ProceedingJoinPoint继承JoinPoint子接口,它只是新增了两个用于执行连接点方法的方法:
proceed() throws java.lang.Throwable:通过反射执行目标对象的连接点处的方法;
proceed(java.lang.Object[] args) throws java.lang.Throwable:通过反射执行目标对象连接点处的方法,使用新的入参替换原来的入参。
使用介绍:
private Log logger = LogFactory.getLog(LogAspect.class);
public void doSystemLog(JoinPoint point) throws Throwable {
Object[] param = point.getArgs();
for(int i=0;i<param.length;i++){
System.out.println("参数"+i+"=: "+param[i]);
}
Method method = null;
String methodName = point.getSignature().getName();
System.out.println("签名方法:================"+methodName);
if (!(methodName.startsWith("set") || methodName.startsWith("get")||methodName.startsWith("query"))){
Class targetClass = point.getTarget().getClass();
System.out.println("类名:================"+targetClass.getName());
try {
method = targetClass.getMethod(methodName, param[0].getClass());
} catch (Exception e) {
// TODO: handle exception
}
System.out.println("类方法:================"+method);
if (method != null) {
boolean hasAnnotation = method.isAnnotationPresent(Log.class);
if (hasAnnotation) {
Log annotation = method.getAnnotation(Log.class);
String methodDescp = annotation.operationType()+annotation.operationName();
if (logger.isDebugEnabled()) {
logger.debug("Action method:" + method.getName() + " Description:" + methodDescp);
}
}
}
}
}