copy data to map

将对象数据复制到Map对象

Map map= new HashMap();
Class type = bean.getClass();
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);
        if (result != null) {
            map.put(propertyName, result);
        }
    }
}
        积极竞争
    不惧失败
学习提升
原文地址:https://www.cnblogs.com/acmez/p/14958937.html