我正在尝试使用java将DO转换为DTO,并在开始编写自己的工具之前寻找自动化工具。我只是想知道是否有同样的免费工具可用。
当前回答
使用Apache commons beanutils:
静态无效copyProperties(对象dest,对象origin) -将所有属性值从源bean复制到目标bean 属性名为的情况 相同。
http://commons.apache.org/proper/commons-beanutils/
其他回答
另一个是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
我建议您试试JMapper框架。
它是一个Java bean到Java bean的映射器,允许您使用注释和/或XML动态地执行数据传递。
使用JMapper你可以:
创建并充实目标对象 对映射应用特定的逻辑 自动管理XML文件 实现1到N和N到1的关系 实现显式转换 应用继承的配置
我很高兴添加Moo作为一个选项,尽管很明显我对它有偏见: http://geoffreywiseman.github.com/Moo/
它在简单的情况下很容易使用,在更复杂的情况下也很有能力,尽管我仍然可以想象在一些方面对它进行进一步的改进,以解决更复杂的问题。
你也可以尝试基于Dozer的映射框架,但是用Excel来声明映射。他们有一些工具和额外的很酷的功能。 查看网址:http://openl-tablets.sf.net/mapper
推荐文章
- JavaFX应用程序图标
- Java:强/软/弱/幻影引用的区别
- 在序列化和反序列化期间JSON属性的不同名称
- 获取Android设备名称
- Gradle代理配置
- 如何获得具有已知资源名称的资源id ?
- 在Android上将字符串转换为整数
- 为什么“System.out。”println“工作在Android?
- 在Java中什么时候使用可变参数?
- Mockito的argumentCaptor的例子
- 我如何告诉Spring Boot哪个主类用于可执行jar?
- 如何将Java8流的元素添加到现有的列表中
- 在Java 8中是否可以转换流?
- 不区分大小写的字符串作为HashMap键
- 什么是maven中的“pom”打包?