How to skip lines with ItemReader in Spring-Batch?

后端 未结 5 820
陌清茗
陌清茗 2021-01-16 15:39

I have a custom item reader that transforms lines from a textfile to my entity:

public class EntityItemReader extends AbstractItemStreamItemReader

        
5条回答
  •  广开言路
    2021-01-16 16:30

    We can handle it via a custom Dummy Object.

    private final MyClass DUMMYMyClassObject ;
    
    private MyClass(){
       // create blank Object .
    }
    
    public static final MyClass getDummyyClassObject(){
      if(null == DUMMYMyClassObject){
          DUMMYMyClassObject = new MyClass();
      }
      return DUMMYMyClassObject ;
     }
    

    And just use the below when required to skip the record in the reader :

    return MyClass.getDummyyClassObject();
    

    The same can be ignored in the processor , checking if the object is blank OR as per the logic written in the private default constructor .

提交回复
热议问题