使用commons-beanutils迭代获取javabean的属性

        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));
            }
        }

 

posted @ 2016-12-06 10:25  魔豆  阅读(2098)  评论(0编辑  收藏  举报