public Map<String, Object> toMap(Object o){
Class c=o.getClass();//用反射获取class对象
Map<String, Object> map=new HashMap<String, Object>();
try {
Field[] fs=c.getDeclaredFields();//将对象内的所有属性都提取出来
for (Field f : fs) {
f.setAccessible(true);//将属性设为可操作
String st=f.get(o)+"";
String str=st.replaceAll(" ", "");
if (str.equals("")||str.equals("null")) {//空值判断
map.put(f.getName(), "");
continue;
}
map.put(f.getName(), st);
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return map;
}