public static Map <String, Object> convertBean (Object bean)
{
Map <String, Object> returnMap;
try
{
Class type = bean.getClass ();
returnMap = new HashMap <String, Object> ();
BeanInfo beanInfo = Introspector.getBeanInfo (type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors ();
for (int i = 0; i < propertyDescriptors.length; i++)
{
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName ();
if (!propertyName.equals ("class"))
{
Method readMethod = descriptor.getReadMethod ();
Object result = readMethod.invoke (bean, new Object[0]);
if (result != null)
{
returnMap.put (propertyName, result);
}
else
{
returnMap.put (propertyName, "");
}
}
}
return returnMap;
}
catch (Exception e)
{
throw new BusinessException ("转换异常" + e.getMessage (), e);
}
}