1 /** 2 * 查询类中符合指定annotation的属性信息 3 * @param objCls 实体类 4 * @param annCls 注解类 5 * @return HashMap<实体属性名, Annontation> 6 */ 7 public static <T extends Annotation> HashMap<String, T> getFieldAnnotationsMsg(final Class<?> objCls,final Class<T> annCls){ 8 HashMap<String, T> ht=new HashMap<String, T>(); 9 for (Class<?> superClass = objCls; superClass != Object.class; superClass = superClass.getSuperclass()) { 10 Field[] fs = superClass.getDeclaredFields(); 11 for (Field f : fs) { 12 if(f.isAnnotationPresent(annCls)){ 13 ht.put(f.getName(),f.getAnnotation(annCls)); 14 } 15 } 16 } 17 return ht; 18 }