111
This commit is contained in:
1 parent
81eca8933a
commit
345f906c35
540 files changed
+494222
-90
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package com.ruoyi.init;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class AnnotationFinder {
|
||||
|
||||
public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType) {
|
||||
// 先在类上查找
|
||||
A annotation = clazz.getAnnotation(annotationType);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
}
|
||||
|
||||
// 然后在方法上查找
|
||||
for (java.lang.reflect.Method method : clazz.getMethods()) {
|
||||
annotation = method.getAnnotation(annotationType);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
|
||||
// 最后在字段上查找
|
||||
for (java.lang.reflect.Field field : clazz.getFields()) {
|
||||
annotation = field.getAnnotation(annotationType);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user