public static Set<Field> getAllFiled(Class<?> entityClass) {

        // 获取本类的所有字段
        Set<Field> fs = new HashSet<Field>();
        for (Field f : entityClass.getFields()) {
            fs.add(f);
        }
        for (Field f : entityClass.getDeclaredFields()) {
            fs.add(f);
        }

        // 递归获取父类的所有字段
        Class<?> superClass = entityClass.getSuperclass();
        if (!superClass.equals(Object.class)) {
            Set<Field> superFileds = getAllFiled(superClass);
            fs.addAll(superFileds);
        }

        return fs;
    }
public static Set < Field > getAllFiled ( Class < ? > entityClass ) { Set < Field > fs = new HashSet < Field > ( ) ; for ( Field f : entityClass . getFields ( ) ) { fs . add ( f ) ; } for ( Field f : entityClass . getDeclaredFields ( ) ) { fs . add ( f ) ; } Class < ? > superClass = entityClass . getSuperclass ( ) ; if ( ! superClass . equals ( Object . class ) ) { Set < Field > superFileds = getAllFiled ( superClass ) ; fs . addAll ( superFileds ) ; } return fs ; }
获取一个类的所有字段

@param entityClass

@return