private static List<Field> getAllField(Class<?> entityClass, List<Field> fieldList) {
if (fieldList == null) {
fieldList = new ArrayList<Field>();
}
if (entityClass.equals(Object.class)) {
return fieldList;
}
Field[] fields = entityClass.getDeclaredFields();
for (Field field : fields) {
//排除静态字段
if (!Modifier.isStatic(field.getModifiers())) {
fieldList.add(field);
}
}
Class<?> superClass = entityClass.getSuperclass();
if (superClass != null
&& !superClass.equals(Object.class)
&& (superClass.isAnnotationPresent(Entity.class)
|| (!Map.class.isAssignableFrom(superClass)
&& !Collection.class.isAssignableFrom(superClass)))) {
return getAllField(entityClass.getSuperclass(), fieldList);
}
return fieldList;
}
获取一个实体类的所有非静态属性
最新推荐文章于 2023-05-26 13:15:44 发布