JavaBean转Map方法

Map<String, Object> fieldMap =new HashMap<String, Object>();

BeanInfo beanInfo = Introspector.getBeanInfo(【javabean类名】.class, Object.class); 
//获取所有的属性描述器 
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); 
for(PropertyDescriptor pd:pds){ 
String key = pd.getName(); 
Method getter = pd.getReadMethod(); 
Object value = getter.invoke(【实例化的javaBean】); 
fieldMap.put(key, value); 
}

 

posted @ 2017-03-14 14:58  望星辰大海  阅读(1782)  评论(0编辑  收藏  举报