/** * 將對象轉化爲map * * @param bean * @param <T> * @return */ private <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key.toString(), beanMap.get(key)); } } return map; } /** * 將list<JavaBean>轉化爲List<Map<String, Object>> * * @param objList * @param <T> * @return */ private <T> List<Map<String, Object>> objectsToMaps(List<T> objList) { List<Map<String, Object>> list = Lists.newArrayList(); if (objList != null && objList.size() > 0) { Map<String, Object> map = null; T bean = null; for (int i = 0, size = objList.size(); i < size; i++) { bean = objList.get(i); map = beanToMap(bean); list.add(map); } } return list; }
主要就是spa
經過net.sf.cglib.beans.BeanMap類中的方法,原理幾乎都是反射code