一.dozerMapper:
1.pom文件添加依赖
<dependency>
<groupId>com.github.dozermapper</groupId>
<artifactId>dozer-core</artifactId>
<version>6.5.0</version>
</dependency>
2.services层
@Autowired
Mapper dozerMapper;
在方法中:
dozerMapper.map(bldSessionsDto, bldSessionsVo);
将参数一Dto对象的属性值复制到参数二Vo对象中,如果属性名称相同则自动复制。
新架构下的对象复制:entity—>VO
Integer id = couponRuleParamVO.getId();
//entity对应数据库表中的字段
CouponRule couponRule = couponRuleDao.selectByPrimaryKey(id);
//VO对应前台需要显示的字段
CouponRuleDetailVO couponRuleDetailVO = new CouponRuleDetailVO();
//将参数一entity,复制到参数二VO中,只有相同类型相同属性名的属性会自动复制
BeanUtil.copyProperties(couponRule,couponRuleDetailVO);
二.CGlib:
BeanUtil
工具类中:
public static void copyProperties(Object source, Object target, Converter converter) {
BeanCopier copier = BeanCopier.create(source.getClass(), target.getClass(), true);
copier.copy(source, target, converter);
}