SpringAOP里JoinPoint常用方法總結


@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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM