@Before("customerJoinPointerExpression()") public void beforeMethod(JoinPoint joinPoint){ joinPoint.getSignature().getName(); // 獲取目標方法名 joinPoint.getSignature().getDeclaringType().getSimpleName(); // 獲取目標方法所屬類的簡單類名 joinPoint.getSignature().getDeclaringTypeName(); // 獲取目標方法所屬類的類名 joinPoint.getSignature().getModifiers(); // 獲取目標方法聲明類型(public、private、protected) Object[] args = joinPoint.getArgs(); // 獲取傳入目標方法的參數,返回一個數組 joinPoint.getTarget(); // 獲取被代理的對象 joinPoint.getThis(); // 獲取代理對象自己
}
// 獲取目標方法上的注解 private <T extends Annotation> T getMethodAnnotation(ProceedingJoinPoint joinPoint, Class<T> clazz) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method method = methodSignature.getMethod(); return method.getAnnotation(clazz); }