简体   繁体   English

复杂对象列表的推土机映射

[英]Dozer mapping of Lists of Complex Object

Is there a way to map one List of objects to one List of objects ids? 有没有一种方法可以将一个对象列表映射到一个对象列表ID? I have the following objects: 我有以下对象:

public class Role implements Serializable {
    private List<Section> sections;
    //getters and setters
    ...
}

public class Section {
    private Long id;
    //getters and setters
    ...
}

public class RoleDTO implements Serializable {
    private List<Long> sections;
    //getters and setters
    ...
}

How can i map this with Dozer XML? 如何使用Dozer XML进行映射?

Note: This is not an answer... more of a wish 注意:这不是答案...更多是希望

It would be nice if dozer supported groovy's spread operator . 如果推土机支持Groovy的传播算子,那将是很好的。 This would be a nice feature request 这将是一个不错的功能要求

eg: 例如:

<field>
    <a>sections*.id</a>
    <b>sections</b>
</field>

You can use a custom converter 您可以使用自定义转换器

Dozer XML 推土机XML

<field custom-converter-id="mySectionsConverter">
  <a>sections</a>
  <b>sections</b>
</field>

Spring XML 春季XML

<bean id="mapper" class="org.dozer.spring.DozerBeanMapperFactoryBean">
    <property name="mappingFiles" value="..." />
    <property name="customConvertersWithId">
        <map>
           <entry key="mySectionsConverter" value-ref="..." />
        </map>
    </property>
</bean>

Note: I'm just in the process of removing dozer from my application because I feel that it complicates things. 注意:我正在从应用程序中删除推土机,因为我觉得这很复杂。 In my opinion a simple java POJO converter class does a much better job than all this XML, custom converters and spring wiring. 在我看来,简单的java POJO转换器类比所有这些XML,自定义转换器和spring接线要好得多。 I've also found cases where it was impossible to reuse a value in a nested converter which caused multiple database hits which weren't required with the POJO solution. 我还发现了无法在嵌套转换器中重用某个值的情况,这会导致多个数据库命中,而POJO解决方案则不需要。

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

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