1700471184
1700471185
BeanInfo beanInfo=Introspector.getBeanInfo(bean.getClass());
1700471186
1700471187
//获得属性描述
1700471188
1700471189
PropertyDescriptor[]descriptors=beanInfo.getPropertyDescriptors();
1700471190
1700471191
//遍历所有属性
1700471192
1700471193
for(PropertyDescriptor des:descriptors){
1700471194
1700471195
//属性名称
1700471196
1700471197
String fieldName=des.getName();
1700471198
1700471199
//读取属性的方法
1700471200
1700471201
Method getter=des.getReadMethod();
1700471202
1700471203
//读取属性值
1700471204
1700471205
Object fieldValue=getter.invoke(bean,new Object[]{});
1700471206
1700471207
if(!fieldName.equalsIgnoreCase(“class”)){
1700471208
1700471209
result.put(fieldName,fieldValue);
1700471210
1700471211
}
1700471212
1700471213
}
1700471214
1700471215
}catch(Exception e){
1700471216
1700471217
//异常处理
1700471218
1700471219
}
1700471220
1700471221
return result;
1700471222
1700471223
}
1700471224
1700471225
//把HashMap的值返回到bean中
1700471226
1700471227
public static void restoreProp(Object bean,HashMap<String,Object>propMap){
1700471228
1700471229
try{
1700471230
1700471231
//获得Bean描述
1700471232
1700471233
BeanInfo beanInfo=Introspector.getBeanInfo(bean.getClass());
[
上一页 ]
[ :1.700471184e+09 ]
[
下一页 ]