至于十万个为什么,我们跟着源代码来看,以及各种拷贝工具的性能效率;
对比工具如下:
1:apache common-beanUtils
2:Spring beanUtils
3:CGLib(实现converter与不实现converter情况,提供缓存BeanCopier提升性能)
4:Mapstruct
附上阿里规约:
效率:getter/setter > Mapstruce > CGLib > Spring >apache common-beanUtils …;
推荐直接定义转换类和方法可使用 IDEA 插件自动填充 get / set 函数。
简述:
commons 包下的BeanUtils进行属性拷贝性能较差,切换成Spring提供的BeanUtils性能明细有提升;如果想看到很明细的对比,则使用性能测试或基准测试即可
准备环境及数据
JDK1.8
commons-beanutils 1.8.1
spring-core 5.3.5
mapstruct-jdk8 -》mapstruct 1.3.1.Final
mapstruct-processor -》mapstruct 1.3.1.Final