论坛首页 入门技术论坛

把Map对象中的值拷贝给一个实体bean

浏览 2858 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-01-06   最后修改:2009-01-06

下面的知识一个代码片断,最重要的就是那段循环代码,可以根据具体情况进行改造

把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());
  }

   发表时间:2009-01-06  
最愚昧的做法, 哈哈
0 请登录后投票
   发表时间:2009-01-06   最后修改:2009-01-06
Point o = new Point();
Map m = new HashMap();
map.put("xline","10");
map.put("yline","15");

BeanUtils.populate(o, m);

log.debug(o.getXline());
log.debug(o.getYline());
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics