获取类属性值,当前类,父类
public static List<Field> getAllDeclaredFields(Class<?> clazz) { List<Field> allFields = new ArrayList<>(); Class<?> superClass = clazz.getSuperclass(); // 获取当前类声明的所有字段 Field[] declaredFields = clazz.getDeclaredFields(); allFields.addAll(Arrays.asList(declaredFields)); // 如果存在父类,则递归获取父类的字段 if (superClass != null) { allFields.addAll(getAllDeclaredFields(superClass)); } return allFields; }