一、引入包
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
另一个包是spring框架中自带
二、使用包
注意:属性复制,不同jar中的方法,用法不一样。 |
1、import org.apache.commons.beanutils.BeanUtils;(常用)
BeanUtils.copyProperties(entity1,entity2);
· entity2中的值赋给entity1 |
2、import org.springframework.beans.BeanUtils;
BeanUtils.copyProperties(entity1,entity2);
· entity1中的值赋给entity2 |
三、作用
· 使得对实体的操作减少set、get操作,实现全属性复制 · 另还有部分实体属性个数匹配问题正测试中 |