遍历实体类属性

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

原文地址:https://www.cnblogs.com/yuezeyuan/p/7597680.html