Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
Object[] args = joinPoint.getArgs();
//参数注解,1维是参数,2维是注解
Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < annotations.length; i++) {
Object param = args[i];
Annotation[] paramAnn = annotations[i];
//参数为空,直接下一个参数
if(param == null || paramAnn.length == 0){
continue;
}
for (Annotation pAnnotation : paramAnn) {
//这里判断当前注解是否为Test.class
if(pAnnotation.annotationType().equals(MyField.class)){
//do something
MyField myField = (MyField) pAnnotation;
String value = myField.value();
if ("url".equals(value)){
originalFileName = (String) param;
break;
}
}
}}
aop获取参数上的注解
最新推荐文章于 2023-07-01 18:27:11 发布