public static Map transBean2Map(Object obj)
{
if(obj == null)
return null;
Map map = new HashMap();
try
{
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor propertyDescriptors[] = beanInfo.getPropertyDescriptors();
PropertyDescriptor apropertydescriptor[] = propertyDescriptors;
int i = apropertydescriptor.length;
for(int j = 0; j < i; j++)
{
PropertyDescriptor property = apropertydescriptor[j];
String key = property.getName();
if(!key.equals("class"))
{
Method getter = property.getReadMethod();
Object value = getter.invoke(obj, new Object[0]);
map.put(key, value);
}
}
}
catch(Exception e)
{
System.out.println((new StringBuilder()).append("transBean2Map Error ").append(e).toString());
}
return map;
}