public static <T> Map ClassToMap(T className, Class<?> entityClass) {
List<Field> fieldList = new ArrayList<>() ;
Class tempClass = entityClass;
while (tempClass != null) {//当父类为null的时候说明到达了最上层的父类(Object类).
fieldList.addAll(Arrays.asList(tempClass .getDeclaredFields()));
tempClass = tempClass.getSuperclass(); //得到父类,然后赋给自己
}
for (Field f:fieldList) {
System.out.println("getFields---"+f.getName());
}
}
01-07
2157
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)