Apache BeanUtils与Spring BeanUtils的拷贝性能比较

本文对比了Apache BeanUtils和Spring BeanUtils在对象拷贝时的性能,通过测试发现Apache BeanUtils的拷贝耗时显著长于Spring BeanUtils,尤其在大量字段的JavaBean中,差距更大。同时,文章提到了其他对象拷贝工具如MapStruct、Dozer和ModelMapper等。
摘要由CSDN通过智能技术生成

Apache BeanUtils需要引入的包:

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.4</version>
        </dependency>

测试同一个对象使用两种拷贝方法的耗时,具体代码如下,

 @Test
    void Copy() throws InvocationTargetException, IllegalAccessException {

        UserInfo userData = this.userInfoService.getUserData("0951d015472946fcbc039f9dff6f13c3");
        UserInfo springBean = new UserInfo();
        long springBegin = System.currentTimeMillis();
        BeanUtils.copyProperties(userData,springBean);
        long springAfter = System.currentTimeMillis();
        System.out.println("共耗时" + (springAfter - springBegin) + "毫秒");


        UserInfo apacheBean = new UserInfo();
        long apacheBegin = System.currentTimeMillis();
        org.apache.commons.beanutils.BeanUtils.copyProperties(apacheBean,userData);
        long apacheAfter = System.currentTimeMillis();
        System.out.println("共耗时" + (apacheAfter - apacheBegin) + "毫秒");

    }

拷贝的对象UserInfo,六个字段,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值