项目中经常遇到 do->vo 等需要转换输出,但是beanUtils 效率不是很高,并且还要手写,效率不高,这里分享一个很好用的方法。推荐使用Mapstruct。
使用起来也很简单啦,基本没有什么学习成本。
第一步,添加依赖
<!--mapStruct依赖 高性能对象映射-->
<!--mapstruct核心-->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.0.Beta2</version>
</dependency>
<!--mapstruct编译-->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.0.Beta2</version>
</dependency>
第二步,创建转换接口
package com.stone.cn.mapstruct;
import com.stone.cn.domain.SysUser;
import com.stone.cn.vo.SysUserVo;