Spring Batch如何执行“跳过”或不考虑编写?

时间:2019-04-15 20:25:14

标签: spring spring-batch

我已经遍历了许多链接,例如:https://docs.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages,只是想在将记录写入MongoDB之前先验证处理器中的记录。

我在500Oracle DB记录中有162th条记录,下面的代码的第1行满足了 ,之后没有其他记录被考虑 ,因此我应该获得480条记录,而不是500条记录,我想跳过的20条记录是因为它的EFFECTIVE_DATE为空,我不希望这样做不想考虑写。

public class StudentRowMapper implements RowMapper<Student> {

    @Override
    public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
        if(rs.getString("EFFECTIVE_DATE") == null) { //Line-1
            return null;
        }
        else {
            Student Student = new Student();
            Student.setRowIdObject(rs.getInt("PK_ID"));
            .............
            .............
            .............
            .............

            return Student;
        }   
    }
} 

2 个答案:

答案 0 :(得分:0)

  

在将记录写入MongoDB之前只是想验证处理器中的记录。

ValidatingItemProcessor是您要寻找的。它使您可以在将项目传递给编写者之前验证它们并对其进行跳过或过滤(请参阅filter参数)。

答案 1 :(得分:0)

同意@Mahmoud,您也可以:

  1. 在您的mongodb阅读器查询中添加此过滤器:“ {EFFECTIVE_DATE:null}”
  2. 在处理器中返回null