使用commons-beanutils迭代獲取javabean的屬性

魔豆發表於2016-12-06
        NoteEntity entity = new NoteEntity();
        entity.setNote001("a1");
        entity.setNote002("a2");
        entity.setNote003("a3");

        java.lang.reflect.Field[] fields = entity.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            String name = fields[i].getName();
            if(PropertyUtils.isReadable(entity, name) && PropertyUtils.isWriteable(entity, name)) {
                System.out.println(name + "___" + BeanUtils.getProperty(entity, name));
            }
        }

 

相關文章