//获取该注解对象的属性值
public static Object getAnnotationValue(Annotation annotation, String property) {
Object result = null;
if (annotation != null) {
InvocationHandler invo = Proxy.getInvocationHandler(annotation); //获取被代理的对象
Map map = (Map) getFieldValue(invo, "memberValues");
if (map != null) {
result = map.get(property);
}
}
return result;
}
public static <T> Object getFieldValue(T object, String property) {
if (object != null && property != null) {
Class<T> currClass = (Class<T>) object.getClass();
try {
Field field = currClass.getDeclaredField(property);
field.setAccessible(true);
return field.get(object);
} catch (NoSuchFieldException e) {
throw new IllegalArgumentException(currClass + " has no property: " + property);
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
java通过Annotation对象获取注解属性的值
最新推荐文章于 2024-07-11 01:11:12 发布