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

转载请注明:WebLogic Android 博客 » Apache BeanUtils 妙用