简体   繁体   English

可配置的对象到对象映射Java / Spring

[英]Configurable Object to Object map Java/Spring

I haven't been able to find any good examples, or a direction to go for this. 我还没有找到任何好的例子,也没有找到前进的方向。 But essentially I want to be able to create a configurable object to object mapping interface. 但实际上,我希望能够创建一个可配置的对象到对象映射接口。 I don't want to hardcode the fields that should be mapped to one another, but rather give users an interface to be able to say fieldA from objectA maps to fieldB from objectB. 我不想对应该相互映射的字段进行硬编码,而是给用户一个接口,使用户能够说出objectA的fieldA映射到objectB的fieldB。

These configuration settings can be persisted in SQL, or an XML file, doesn't really matter to me. 这些配置设置可以保存在SQL或XML文件中,对我而言并不重要。 This is a Spring Boot application. 这是一个Spring Boot应用程序。

I was using Orika for the mapping currently, but I don't know how to make it configurable. 我目前正在使用Orika进行映射,但是我不知道如何使其可配置。 Am I on the right track, or does it not have that capability? 我是在正确的轨道上,还是没有这种能力? Would a CustomMapper be what I need to do? 我需要做CustomMapper吗? Looking for some good examples, or the right direction. 寻找一些好的例子或正确的方向。

You can give Dozer a try. 您可以尝试推土机 It provides full automation of mapping process and allows handling of complicated mapping cases. 它提供了映射过程的完全自动化,并允许处理复杂的映射案例。 Usually, all this flexibility comes at a price of reduced performance, but is maybe good enough in your case. 通常,所有这些灵活性都以降低性能为代价,但对于您的情况来说可能就足够了。

Mappings are usually set using XML files. 映射通常使用XML文件设置。 In later versions, Dozer also supports mappings via API and via Annotations. 在更高版本中,推土机还支持通过API和注释来进行映射。 Check their website for more info. 检查他们的网站以获取更多信息。 Dozer also has a Spring framework integration . Dozer还具有Spring框架集成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM