zoukankan      html  css  js  c++  java
  • BeanUtils.copyProperties(productInfo, productInfoVO);

    一:spring的工具类方法:BeanUtils.copyProperties(orderMasterDTO, orderMasterDO);

    作用:将orderMasterDTO对象中的属性值,赋值到orderMasterDO中,其主要目的是利用反射机制对JavaBean的属性进行拷贝。

        /**
         * Copy the property values of the given source bean into the target bean.
         * <p>Note: The source and target classes do not have to match or even be derived
         * from each other, as long as the properties match. Any bean properties that the
         * source bean exposes but the target bean does not will silently be ignored.
         * <p>This is just a convenience method. For more complex transfer needs,
         * consider using a full BeanWrapper.
         * @param source the source bean
         * @param target the target bean
         * @throws BeansException if the copying failed
         * @see BeanWrapper
         */
        public static void copyProperties(Object source, Object target) throws BeansException {
            copyProperties(source, target, null, (String[]) null);
        }

    二:好处:

    不使BeanUtils.copyProperties(orderMasterDTO, orderMasterDO)方法的话,传统的做法是:手动将orderMasterDTO的属性值set到orderMasterDO中

    OrderMasterDO orderMasterDO = new OrderMasterDO();
    orderMasterDO.setOrderId(orderMasterDTO.getOrderId());
    orderMasterDO.setBuyerName(orderMasterDTO.getBuyerName());
    orderMasterDO.setOrderStatus(orderMasterDTO.getOrderStatus());
    orderMasterDO.setCreateTimestamp(orderMasterDTO.getCreateTimestamp());
    orderMasterDO.setUpdateTimestamp(orderMasterDTO.getUpdateTimestamp());

    而使用了BeanUtils的工具方法,只需BeanUtils.copyProperties(orderMasterDTO, orderMasterDO)就可以ojbk,简单方便多了。

    注意:要注意该方法使用的地方,不然很有可能出现属性值丢失的问题

  • 相关阅读:
    比较全的屏幕信息
    使用div实现progress进度条
    选项卡效果的菜单栏
    javascript写的轮播图
    centos6.5 命令行配置无线上网
    CentOS 6.5 BCM43142 80211无线网卡驱动安装
    [数据库] windows server 2003下mysql出现10048错误的解决办法 Can't connect to MySQL server on '127.0.0.1' (10048)
    桥接模式-多台虚拟机配置(重要)
    VMware虚拟机中如何配置静态IP
    MySQL5.7 mysql.user创建用户
  • 原文地址:https://www.cnblogs.com/quan-coder/p/10186770.html
Copyright © 2011-2022 走看看