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

 

posted @ 2017-08-09 10:54  JhonMr  阅读(12265)  评论(0编辑  收藏  举报