変数マッピングを使用すると、Dozer 設定内の変数定義の値を、ソースフィールドの値を使用する代わりにターゲットフィールドにマップできます。 これは、他のマッピングフレームワークの定数マッピングと同等で、リテラル値をターゲットフィールドに割り当てることができます。 変数マッピングを使用するには、マッピング設定内で変数を定義してから、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