public static Map ConvertObjToMap(Object obj){
Map<String,Object> reMap = new HashMap<String,Object>();
if (obj == null)
return null;
Field[] fields = obj.getClass().getDeclaredFields();
try {
for(int i=0;i<fields.length;i++){
try {
Field f = obj.getClass().getDeclaredField(fields[i].getName());
f.setAccessible(true);
Object o = f.get(obj);
if(o == null){
o = "";
}else{
o = String.valueOf(o);
}
reMap.put(fields[i].getName(), String.valueOf(o));
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return reMap;
}
posted on 2015-08-31 19:52
藤本蔷薇 阅读(1010)
评论(0) 编辑 收藏