反射屬性值

Field[] fields = bean.getClass().getDeclaredFields();
try {
     for (int i = 0; i < fields.length; i++) {
     Field f = fields[i];
     // 設置些屬性是可以訪問的
     f.setAccessible(true);
          logger.info(f.getName() + "  -  " + f.get(bean));
     }
} catch (Exception e) {
     e.printStackTrace();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章