This commit is contained in:
lu7213 committed 2025-12-02 23:07:47 +08:00
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;
}
}