//*
将JavaBean对象转换为Map
*
* @param bean转换的JavaBean对象
* @return转换的Map对象
* @throws IntrospectionException类属性分析失败时
* @ throwsillegalaccessexceptionjavabean实例化失败时
调用* @ throwsinvocationtargetexception属性的setter方法将失败
*/
公共统计转换bean (对象bean )。
throws IntrospectionException,IllegalAccessException,InvocationTargetException {
Class type=bean.getClass (;
Map returnMap=new HashMap (;
beaninfobeaninfo=introspect or.getbeaninfo (type );
property descriptor [ ] property descriptors=bean info.getproperty descriptors (;
for(intI=0; i propertyDescriptors.length; I ) {
propertydescriptordescriptor=property descriptors [ I ];
string property name=descriptor.getname (;
if (! propertyname.equals('class ' ) }{
methodreadmethod=descriptor.getreadmethod (;
对象结果=read method.invoke (bean,new Object[0];
if (结果!=空) {
Returnmap.put(propertyname,result );
} else {
Returnmap.put(propertyname,'');
}
}
}
返回返回返回映射;
}
译文: 3359 www.cn blogs.com/Lin sky/p/12015199.html