JoinPoint 获取方法注解
作者:互联网
JoinPoint 获取方法注解
方法名 | 功能 |
---|---|
Signature getSignature(); | 获取封装了部署信息的对象,在该对象中可以获取到目标方法名,所属类的Class等信息 |
Object[] getArgs(); | 获取传入目标方法的参数对象 |
Object getTarget(); | 获取被代理的对象 |
Object getThis(); | 获取代理对象 |
// 第一种
try {
Class<?> clazz = joinPoint.getTarget().getClass();
String methodName = joinPoint.getSignature().getName();
Class<?>[] parameterTypes = ((MethodSignature) joinPoint.getSignature()).getMethod().getParameterTypes();
Method method = clazz.getMethod(methodName, parameterTypes);
PostMapping postMapping = method.getAnnotation(PostMapping.class);
String[] paths = postMapping.value();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
// 第二种
String[] paths = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(PostMapping.class).value();
标签:JoinPoint,String,joinPoint,getSignature,获取,Object,getMethod,注解 来源: https://www.cnblogs.com/Zzzyyw/p/16350954.html