/**
* 使用reflect进行转换,javabean对象转map集合
*
* @param obj
* @return map集合
* @throws IllegalAccessException java.lang.IllegalAccessException
* @throws InstantiationException java.lang.InstantiationException
*/
public static Map<String, Object> objectToMap(Object obj) throws Exception {
if (obj == null) {
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
Field[] declaredFields = obj.getClass().getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
map.put(field.getName(), field.get(obj));
}
return map;
}