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,六个字段,