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);
}
上一篇:centos和ubuntu下使用cron设置定时任务


下一篇:搭建windows下filezilla FTP服务器