通过反射获取对象里所有属性,并置为可访问循环即可
···
public MapobjectToMap(Object obj)throws Exception {
if (obj ==null) {
return null;
}
Map map =new HashMap();
Field[] declaredFields = obj.getClass().getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
map.put(field.getName(), field.get(obj));
}
return map;
}
···