}
public static T populate(Map<String, Object> map, Class clz) throws Exception {
T obj = clz.newInstance();
//拿到 BeanInfo
BeanInfo beanInfo = Introspector.getBeanInfo(clz);
//通过 beaninfo 获取所有的描述器
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
//获取属性的名字
String name = pd.getName();
//判断是否有这个属性
if (map.containsKey(name)){
//获取属性的 写的方法
Method wMethod = pd.getWriteMethod();
if (pd.getPropertyType() == int.class){
wMethod.invoke(obj,Integer.valueOf(map.get(name).toString()));
}else if (pd.getPropertyType() == double.class){
wMethod.invoke(obj,Double.valueOf(map.get(name).toString()));
}else {
wMethod.invoke(obj,map.get(name));
}
}
}
return obj;
}
### 2、方式一升级款
//map转换成Bean,只要Map键和JavaBean属性名一致即可,解决mapToBean因为单个首字母大写,映射找不到属性的问题
publi