下面的知识一个代码片断,最重要的就是那段循环代码,可以根据具体情况进行改造
把Map对象map中的值拷贝给一个实体bean
实体bean 实体对象 = load(实体bean.class, id);//首先load出实体bean的一个po
Iterator iterMap = map.entrySet().iterator();
while (iterMap.hasNext()) {
Map.Entry entry = (Map.Entry) iterMap.next();
PropertyDescriptor pd = org.springframework.beans.BeanUtils.getPropertyDescriptor(实体bean.class, entry.getKey().toString());
if (pd == null || pd.equals("")) {
throw new RuntimeException("输入的要修改的属性与实体属性不匹配"
+ entry.getKey().toString());
}
BeanUtils.setProperty(实体对象, (String) entry.getKey(),entry.getValue());
}