通过变量映射,您可以将 Dozer 配置中的变量定义值映射到 target 字段,而不使用 source 字段的值。 这等同于其他映射框架中的恒定映射,您可以在其中分配字面值到 target 字段。 要使用变量映射,只需在映射配置中定义变量,然后从 VariableMapper 类映射到您选择的目标字段:
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
<configuration>
<variables>
<variable name="CUST_ID">ACME-SALES</variable>
</variables>
</configuration>
<mapping>
<class-a>org.apache.camel.component.dozer.VariableMapper</class-a>
<class-b>org.example.Order</class-b>
<field custom-converter-id="_variableMapping" custom-converter-param="${CUST_ID}">
<a>literal</a>
<b>custId</b>
</field>
</mapping>
</mappings>
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
<configuration>
<variables>
<variable name="CUST_ID">ACME-SALES</variable>
</variables>
</configuration>
<mapping>
<class-a>org.apache.camel.component.dozer.VariableMapper</class-a>
<class-b>org.example.Order</class-b>
<field custom-converter-id="_variableMapping" custom-converter-param="${CUST_ID}">
<a>literal</a>
<b>custId</b>
</field>
</mapping>
</mappings>
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow