`
loseone
  • 浏览: 33250 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Apache BeanUtils 妙用

阅读更多

1) 从 FormBean 复制值到 JavaBean 或者互相复制.
            TdepartmentForm deptForm = (TdepartmentForm) form;
            Tdepartment tdepartment = new Tdepartment();
            BeanUtils.copyProperties(tdepartment, deptForm);
2) 复制实体(实体一般是动态的代理类)为 ValueObject 防止原始实体的值被更新掉
            Tproviderbill billVO = new Tproviderbill();
            BeanUtils.copyProperties(billVO, dao.getBill(1));// 复制属性, 防止原实体被修改
            if(billVO.xxx == xxx) {
                billVO.setName(“aaaa”);
            }
        // 保存查询结果
        request.setAttribute("bill", billVO);

不过, 又有人指出 CGLIB 复制 Bean 速度更快, 效率更高(目前尚未做相关测试)!

static BeanCopier copy = BeanCopier.create(Bean.class, Bean2.class, false);

void beanCopies(Object source , Object target){
    copy.copy(source, target, null);
}



BeanSoft 2009-04-29 19:19 发表评论
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics