1.pom引入

<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.8</version>
</dependency>

2.将DAO对象转为DTO对象

User user = new User();
user.setId(1L);
user.setNickname("张三");
user.setEmail("101@qq.com");
user.setHonor("测试荣誉");
ModelMapper modelMapper = new ModelMapper();
UserDTO userDTO = modelMapper.map(user, UserDTO.class);
System.out.println(userDTO);

3.工具类

public class ModuleHelper {

    private static final ModelMapper modelMapper;

    static {
modelMapper = new ModelMapper();
// modelMapper.createTypeMap(String.class, Date.class);
// modelMapper.addConverter(toStringDate);
// modelMapper.getTypeMap(String.class, Date.class).setProvider(localDateProvider);
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
} private ModuleHelper() {
} public static <D, T> D map(final T entity, Class<D> outClass) {
return modelMapper.map(entity, outClass);
} public static <D, T> List<D> mapAll(final Collection<T> entityList, Class<D> outCLass) {
return entityList.stream()
.map(entity -> map(entity, outCLass))
.collect(Collectors.toList());
} public static <S, D> D map(final S source, D destination) {
modelMapper.map(source, destination);
return destination;
}
}

最新文章

  1. 移动站应该尝试百度MIP的五个原因
  2. MAC下反編譯安卓APK
  3. android4.x获取(也可监测)外置sd路径和读写
  4. (引用)web安全测试
  5. [转]CodeSmith和PowerDesigner的使用安装和数据库创建
  6. php判断爬虫
  7. explicit构造函数的作用
  8. 为什么我们使用192.168.0.1作为内网ip
  9. ibatis面试笔记
  10. 验证docker的Redis镜像也存在未授权访问漏洞
  11. 初识Treap
  12. Python 收集Twitter时间序列数据
  13. ubuntu如何进入local、bin目录
  14. JS语句
  15. Abp(.NetCore)开发与发布过程
  16. python实战--数据结构二叉树
  17. HTML&amp;CSS_基础04
  18. 《团队-爬取豆瓣top250-开发文档》
  19. Windows Server2008、IIS7启用CA认证及证书制作完整过程
  20. Vue(六)过滤器

热门文章

  1. 源码篇:ThreadLocal的奇思妙想(万字图文)
  2. 基于IMU与磁力计的手势提取手套-原理及其实现
  3. Typora+PicGo+cos图床打造开发者文档神器
  4. hdu4665 DFS
  5. UVA11039
  6. ThinkPHP5中出现unserialize()报错
  7. StreamReader &amp; StreamWriter
  8. 【技术博客】基于vue的前端快速开发(工具篇)
  9. Spring Cloud Alibaba(12)---Gatway概述、简单示例
  10. MySQL之数据定义语言(DDL)