遍历实体类属性

public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
// TODO Auto-generated method stub
Person p=new Person(3,"阿三");
for (Field field :p.getClass().getDeclaredFields()) {
field.setAccessible(true);
System.out.println(field.getName() + ":" +field.get(p));
}
}

 

posted @ 2017-09-26 17:00  无月行  阅读(180)  评论(0编辑  收藏  举报