我正在尝试使用java将DO转换为DTO,并在开始编写自己的工具之前寻找自动化工具。我只是想知道是否有同样的免费工具可用。
当前回答
另一个是Orika - https://github.com/orika-mapper/orika
Orika is a Java Bean mapping framework that recursively copies (among other capabilities) data from one object to another. It can be very useful when developing multi-layered applications. Orika focuses on automating as much as possible, while providing customization through configuration and extension where needed. Orika enables the developer to : Map complex and deeply structured objects "Flatten" or "Expand" objects by mapping nested properties to top-level properties, and vice versa Create mappers on-the-fly, and apply customizations to control some or all of the mapping Create converters for complete control over the mapping of a specific set of objects anywhere in the object graph--by type, or even by specific property name Handle proxies or enhanced objects (like those of Hibernate, or the various mock frameworks) Apply bi-directional mapping with one configuration Map to instances of an appropriate concrete class for a target abstract class or interface Handle reverse mappings Handle complex conventions beyond JavaBean specs. Orika uses byte code generation to create fast mappers with minimal overhead.
其他回答
我的ModelMapper是另一个值得一试的库。ModelMapper的设计不同于其他库,因为它:
通过智能匹配源和目标属性自动映射对象模型 提供一个重构安全映射API,使用实际代码来映射字段和方法,而不是使用字符串 利用基于约定的配置来简单处理自定义场景
查看ModelMapper网站以获取更多信息:
http://modelmapper.org
另一个是Orika - https://github.com/orika-mapper/orika
Orika is a Java Bean mapping framework that recursively copies (among other capabilities) data from one object to another. It can be very useful when developing multi-layered applications. Orika focuses on automating as much as possible, while providing customization through configuration and extension where needed. Orika enables the developer to : Map complex and deeply structured objects "Flatten" or "Expand" objects by mapping nested properties to top-level properties, and vice versa Create mappers on-the-fly, and apply customizations to control some or all of the mapping Create converters for complete control over the mapping of a specific set of objects anywhere in the object graph--by type, or even by specific property name Handle proxies or enhanced objects (like those of Hibernate, or the various mock frameworks) Apply bi-directional mapping with one configuration Map to instances of an appropriate concrete class for a target abstract class or interface Handle reverse mappings Handle complex conventions beyond JavaBean specs. Orika uses byte code generation to create fast mappers with minimal overhead.
你可以试试Dozer。
Dozer是一个Java Bean到Java Bean的程序 递归复制数据的映射器 从一个物体到另一个物体。通常情况下, 这些Java bean将是不同的 复杂类型。 Dozer支持简单属性 映射,复杂类型映射, 双向映射, 隐式-显式映射,以及 递归的映射。这包括 映射集合属性 还需要在元素处进行映射 的水平。
使用Apache commons beanutils:
静态无效copyProperties(对象dest,对象origin) -将所有属性值从源bean复制到目标bean 属性名为的情况 相同。
http://commons.apache.org/proper/commons-beanutils/
我建议您试试JMapper框架。
它是一个Java bean到Java bean的映射器,允许您使用注释和/或XML动态地执行数据传递。
使用JMapper你可以:
创建并充实目标对象 对映射应用特定的逻辑 自动管理XML文件 实现1到N和N到1的关系 实现显式转换 应用继承的配置
推荐文章
- 如何在Java中打印二叉树图?
- String.format()在Java中格式化双重格式
- com.jcraft.jsch.JSchException: UnknownHostKey
- Java中的操作符重载
- 如何加速gwt编译器?
- 在Hibernate中重新连接分离对象的正确方法是什么?
- 应该……接住环内还是环外?
- 如何格式化Joda-Time DateTime仅为mm/dd/yyyy?
- 如何在POM.xml中引用环境变量?
- 如何在android中复制一个文件?
- 将整数转换为字符串,以逗号表示千
- 接口方法的最终参数-有什么意义?
- Java中的@UniqueConstraint注释
- 如何在清洁模式下运行eclipse ?如果我们这样做会发生什么?
- 获取java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory异常