5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring Batch:Readerで読み込んだItemを読み飛ばしたいとき

Posted at

ItemProcessorを実装して、processメソッドでnullを返すと、Writerに渡らないためスキップされる。

実装例

public class SampleItemProcessor implements ItemProcessor<SampleEntity, SampleEntity> {
	
	/**
	 * 読み飛ばすかどうか
	 */
	@Override
	public SampleEntity process(SampleEntity item) throws Exception {
		if (item.isInvalid()) {
			return null;
		}
		return item;
	}
}

設定例

<batch:step id="sampleStep">
    <batch:tasklet >
        <batch:chunk writer="sampleWriter" reader="sampleReader" processor="sampleItemProcessor" commit-interval="1000" />
    </batch:tasklet>
</batch:step>
<bean id="sampleItemProcessor" class="jp.canetrash.sample.SampleItemProcessor"/>
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?