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

 



如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
posted @   君莫笑我十年游  阅读(2003)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示