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);
}
}
}
标签:map,Map,propertyName,descriptor,propertyDescriptors,result,copy,data 来源: https://www.cnblogs.com/acmez/p/14958937.html