问题描述
我需要读取一个平面文件并创建一个 TRADE java 对象.现在处理器应该基于 TRADE java 对象创建 3 个不同的 java 对象.我必须将这 3 个不同的 java 对象写入 3 个不同的 xml 文件.
i have a requirement to read a flatfile and create a TRADE java object.Now processor should create 3 different java objects based on TRADE java object.i have to write these 3 different java objects to 3 differnt xml files.
我只想根据读取的数据读取 3 个处理器和 3 个写入多个 xml 文件.
simply I want to one read 3 processors and 3 write to multiple xml files based on the read data.
我尝试了复合项编写器,但它会使用相同的对象进行写入.但是我有 3 个不同的对象使用者、信封、交付顺序
I have tried compositeItemWriter but it will take the same object for writing.but i have 3 different object consumer,envelope,deliveryOrder
样本输入:
11000000001F11000000062237 693553467588549
11000000001221000000030237 628525475867698
11000000031110000000562374 687598787668557
11000000001G21000000056237 687557575645346
11000000001F11000000062237 693553467588549
11000000001221000000030237 628525475867698
output 1.
<consumers>
<consumer>
<sequenceNum>1481</sequenceNum>
<sourceSystemBrandId>237</sourceSystemBrandId>
<sourceCid>999000367588</sourceCid>
<preferences>
<preference>
<contentType>Statement</contentType>
<value>E</value>
<distributionChannel>[email protected]</distributionChannel>
</preference>
</preferences>
<deliveryPoints>
<dpvDeliveryPoint>
<dpv>1171783651</dpv>
</dpvDeliveryPoint>
<emailDeliveryPoint>
<email>[email protected]</email>
</emailDeliveryPoint>
</deliveryPoints>
</consumer>
</consumers>
output 2:
<envelopes>
<envelope>
<sourceEnvId>xxxx</sourceEnvId>
<sourceSystemBrandId>xxx</sourceSystemBrandId>
<sourceCid>xxx</sourceCid>
<envelopeData>
<envelopeName>xxx</envelopeName>
<contentType>statement</contentType>
<statementData>
<accountNumber>xxx</accountNumber>
<accountName>xxx</accountName>
<statementAmount/>
<periodStartDate/>
<periodEndDate/>
<date>2017-09-04</date>
</statementData>
<details><detail><name>Class_Email</name><value>xxx</value><type>xxx</type>
</detail></details>
<envelopeDocuments>
<envelopeDocument><docRef>Benhe</docRef></envelopeDocument>
</envelopeDocuments>
<printSuppressed>YES</printSuppressed>
<historicalMail>NO</historicalMail>
<asOfDate>2017-09-04</asOfDate>
</envelopeData>
</envelope>
</envelopes>
output 3:
<deliveryOrder>
<consumer>
<preferences>
<!--1 or more repetitions:-->
<preference>
<contentType>string</contentType>
<value>string</value>
<!--Optional:-->
<effectiveDate>2006-08-19T19:27:14+02:00</effectiveDate>
</preference>
</preferences>
<!--Optional:-->
<details>
<detail>
<name>string</name>
<value>string</value>
</detail>
<detail>
<name>string</name>
<value>string</value>
</detail>
<detail>
<name>string</name>
<value>string</value>
</detail>
</details>
<deliveryPoints>
<unstructuredNameDeliveryPoint>
<name>string</name>
</unstructuredNameDeliveryPoint>
</deliveryPoints>
</consumer>
<envelopeDocuments>
<envelopeDocument>
<docRef>string</docRef>
<docFingerprint>string</docFingerprint>
</envelopeDocument>
</envelopeDocuments>
<printSuppressed>NO</printSuppressed>
<historicalMail>Yes</historicalMail>
<asOfDate>2005-09-12+02:00</asOfDate>
</envelopeData>undefined</deliveryOrder>
感谢您对此的任何帮助.谢谢.
Appreciate any help on this.Thanks.
推荐答案
您对 CompositeItemWriter
很熟悉.但是,根据您所描述的内容,有一个更好的选择,即 ClassifierCompositeItemWriter
.这个 ItemWriter
实现允许你注入一个 Classifier
,你可以实现它来选择你的对象最终开始传递给哪个 ItemWriter
.事实上,我们甚至提供了一个对您有用的 Classifier
实现,SubclassClassifier
.这需要一个类映射作为键,而 ItemWriter
是值.这将允许您将每个对象类型映射到适当的 ItemWriter
.
You're close with the CompositeItemWriter
. However, there is a better option based on what you're describing which is the ClassifierCompositeItemWriter
. This ItemWriter
implementation allows you to inject a Classifier
which you can implement to chose which ItemWriter
your object ends up begin passed to. In fact, we even provide a Classifier
implementation that should be useful for you, the SubclassClassifier
. That takes a map of classes as the key and the ItemWriter
is the value. This will allow you to map each object type to the appropriate ItemWriter
.
这篇关于读取平面文件并写入多个写入不同对象的写入器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!