Java ObjectToMap(对象转MAP)笔记
public static Map<String, Object> ObjectToMapUtil(Object obj){ Map<String,Object> reMap = new HashMap<String,Object>(); Field[] fields = obj.getClass().getDeclaredFields(); for(int i = 0; i < fields.length; i++){ Field subField = obj.getClass().getDeclaredField(fields[i].getName()); subField.setAccessible(true); Object o = subField.get(info); reMap.put(fields[i].getName(), o); }
return reMap; }