问题
how to insert data into multiple tables through ItemWriter. ItemWriter Gets input through ItemReader which selects the data from multiple tables.it should accomplish this in single step. can somebody help?
回答1:
You can use CompositeWriter of Spring Batch
<chunk reader="myReader" writer="compositeWriter" />
Composite writer, seen by your step is no different by other writers, you may look at the chunk definition above.
<bean id="compositeWriter" class="org.springframework.batch.item.support.CompositeItemWriter">
<property name="delegates">
<list>
<ref bean="table1Writer" />
<ref bean="table2Writer" />
</list>
</property>
</bean>
The main speciality of the CompositeWriter is that it gets a list of "delegates" which are usual Spring Batch Writers.
In this case table1Writer and table2Writer will be your implementations of jdbc writers.
来源:https://stackoverflow.com/questions/15805868/how-to-insert-data-into-multiple-tables-through-itemwriter