我正在尝试使用java将DO转换为DTO,并在开始编写自己的工具之前寻找自动化工具。我只是想知道是否有同样的免费工具可用。
当前回答
我的ModelMapper是另一个值得一试的库。ModelMapper的设计不同于其他库,因为它:
通过智能匹配源和目标属性自动映射对象模型 提供一个重构安全映射API,使用实际代码来映射字段和方法,而不是使用字符串 利用基于约定的配置来简单处理自定义场景
查看ModelMapper网站以获取更多信息:
http://modelmapper.org
其他回答
附近有一些图书馆:
Commons-BeanUtils: ConvertUtils -> Utility methods for converting String scalar values to objects of the specified Class, String arrays to arrays of the specified Class. Commons-Lang: ArrayUtils -> Operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]). Spring framework: Spring has an excellent support for PropertyEditors, that can also be used to transform Objects to/from Strings. Dozer: Dozer is a powerful, yet simple Java Bean to Java Bean mapper that recursively copies data from one object to another. Typically, these Java Beans will be of different complex types. ModelMapper: ModelMapper is an intelligent object mapping framework that automatically maps objects to each other. It uses a convention based approach to map objects while providing a simple refactoring safe API for handling specific use cases. MapStruct: MapStruct is a compile-time code generator for bean mappings, resulting in fast (no usage of reflection or similar), dependency-less and type-safe mapping code at runtime. Orika: Orika uses byte code generation to create fast mappers with minimal overhead. Selma: Compile-time code-generator for mappings JMapper: Bean mapper generation using Annotation, XML or API (seems dead, last updated 2 years ago) Smooks: The Smooks JavaBean Cartridge allows you to create and populate Java objects from your message data (i.e. bind data to) (suggested by superfilin in comments). (No longer under active development) Commons-Convert: Commons-Convert aims to provide a single library dedicated to the task of converting an object of one type to another. The first stage will focus on Object to String and String to Object conversions. (seems dead, last update 2010) Transmorph: Transmorph is a free java library used to convert a Java object of one type into an object of another type (with another signature, possibly parameterized). (seems dead, last update 2013) EZMorph: EZMorph is simple java library for transforming an Object to another Object. It supports transformations for primitives and Objects, for multidimensional arrays and transformations with DynaBeans (seems dead, last updated 2008) Morph: Morph is a Java framework that eases the internal interoperability of an application. As information flows through an application, it undergoes multiple transformations. Morph provides a standard way to implement these transformations. (seems dead, last update 2008) Lorentz: Lorentz is a generic object-to-object conversion framework. It provides a simple API to convert a Java objects of one type into an object of another type. (seems dead) OTOM: With OTOM, you can copy any data from any object to any other object. The possibilities are endless. Welcome to "Autumn". (seems dead)
我很高兴添加Moo作为一个选项,尽管很明显我对它有偏见: http://geoffreywiseman.github.com/Moo/
它在简单的情况下很容易使用,在更复杂的情况下也很有能力,尽管我仍然可以想象在一些方面对它进行进一步的改进,以解决更复杂的问题。
我的ModelMapper是另一个值得一试的库。ModelMapper的设计不同于其他库,因为它:
通过智能匹配源和目标属性自动映射对象模型 提供一个重构安全映射API,使用实际代码来映射字段和方法,而不是使用字符串 利用基于约定的配置来简单处理自定义场景
查看ModelMapper网站以获取更多信息:
http://modelmapper.org
还有一个Java映射引擎/框架Nomin: http://nomin.sourceforge.net。
你也可以尝试基于Dozer的映射框架,但是用Excel来声明映射。他们有一些工具和额外的很酷的功能。 查看网址:http://openl-tablets.sf.net/mapper
推荐文章
- 如何格式化Joda-Time DateTime仅为mm/dd/yyyy?
- 如何在POM.xml中引用环境变量?
- 如何在android中复制一个文件?
- 将整数转换为字符串,以逗号表示千
- 接口方法的最终参数-有什么意义?
- Java中的@UniqueConstraint注释
- 如何在清洁模式下运行eclipse ?如果我们这样做会发生什么?
- 获取java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory异常
- Java中的正则表达式命名组
- c#和Java的主要区别是什么?
- 什么是NullPointerException,我如何修复它?
- 在Java中使用“final”修饰符
- 无法在Flutter上找到捆绑的Java版本
- 如何在Kotlin解析JSON ?
- 如何在新的材质主题中改变背面箭头的颜色?