gpt4 book ai didi

java - Dozer - 排除嵌套对象

转载 作者:行者123 更新时间:2023-12-03 21:45:48 27 4
gpt4 key购买 nike

根据此示例,您可以使用 Dozer 进行深度映射:
http://dozer.sourceforge.net/documentation/deepmapping.html

<mapping>
<class-a>com.github.dozermapper.core.vo.deep.SrcDeepObj</class-a>
<class-b>com.github.dozermapper.core.vo.deep.DestDeepObj</class-b>
<field>
<a>srcNestedObj.src1</a>
<b>dest1</b>
</field>
<field>
<a>srcNestedObj.src2</a>
<b>dest2</b>
</field>
<field>
<a>srcNestedObj.srcNestedObj2.src5</a>
<b>dest5</b>
</field>
</mapping>

同样,我想排除几个嵌套的对象和字段,所以我尝试了同样的方法:
<mapping map-id="case1" map-null="false">
<class-a>com.server.dal.entities.ClassA</class-a>
<class-b>com.server.dal.dto.ClassB</class-b>

<field-exclude>
<a>childObj1.childObj2</a>
<b>childObj1.childObj2</b>
</field-exclude>
<field-exclude>
<a>childObj1.childObj3.testMap</a>
<b>childObj1.childObj3.testMap</b>
</field-exclude>
</mapping>

但这并没有按预期工作。有没有其他方法可以排除嵌套对象的字段?

最佳答案

您可以按如下方式排除嵌套对象:

<mapping map-id="caseClassA" map-null="false">
<class-a>com.server.dal.entities.ClassA</class-a>
<class-b>com.server.dal.dto.ClassB</class-b>
<field map-id="excludeSubItem1">
<a>childObj1</a>
<b>childObj1</b>
</field>
</mapping>

<mapping map-id="excludeSubitem1" map-null="false">
<class-a>com.server.dal.entities.ClassChild1</class-a>
<class-b>com.server.dal.dto.ClassChild1</class-b>
<field-exclude>
<a>childObj2</a>
<b>childObj2</b>
</field-exclude>
<field map-id="excludeSubItem2">
<a>childObj3</a>
<b>childObj3</b>
</field>
</mapping>

<mapping map-id="excludeSubitem2" map-null="false">
<class-a>com.server.dal.entities.ClassChild3</class-a>
<class-b>com.server.dal.dto.ClassChild3</class-b>
<field-exclude>
<a>testMap</a>
<b>testMap</b>
</field-exclude>
</mapping>

关于java - Dozer - 排除嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64303652/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com