需要导入的包:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
BeanUtils.copyProperties(target,source);
source —— 复制源 ,有值的。
target —— 赋值目标,空的,赋值给他
导包的时候:import org.apache.commons.beanutils.BeanUtils;
是 阿帕奇的这个jar包, 然后在抛异常。就可以了
但是我需要用本地的一个类去封装这些数据,而且不能通过继承(子类父类)的关系去实现,实际开发中经常会遇到这种情况。怎么办呢?别告诉我你想一个一个 localBean.setUserId(longDistance.getUserId())……, 那我告诉你我要封装的数据其实有二十几个字段,你给我去一个一个set!