[英]Skipping bad rows in file with itemProcessor in spring batch
20180627;PM;ABC;0029;BYX;Technology Inc;;DUMMY;OK;33900;34.3;1162770;CT;;;;;;
;;;;;;;;;;;;;;;;;; //bad line
;;;;;;;;;;;;;;;;;; //bad line
;;;;;;;;;;;;;;;;;; //bad line
Is there a way I can skip the bad lines with no data in my MyProcessor
: 有没有一种方法可以跳过MyProcessor
没有数据的不良行:
public class MyProcessor implements ItemProcessor<Row, Price> {
@Override
public Price process(final Row row) throws Exception {
if (row == null) {
}
//Values for lines in file
Price scp = new Price();
//set values
return scp;
}
}
The values of the Row
object are nulls. Row
对象的值为null。 I have seen examples with blank lines, but here I am dealing with colons which is actually the delimiter. 我看到了带有空行的示例,但是在这里我要处理冒号,它实际上是定界符。
Do I have to check for validity of certain fields and prevent object creation and settings ? 我是否必须检查某些字段的有效性并阻止对象的创建和设置? Is there a better way? 有没有更好的办法?
Use a PatternMatchingCompositeLineMapper
to separate valid lines from invalid ones and with a custom FieldSetMapper
map invalid lines to an object called InvalidLine
(just an example). 使用PatternMatchingCompositeLineMapper
可以将有效行与无效行分开,并通过自定义FieldSetMapper
将无效行映射到名为InvalidLine
的对象(仅作为示例)。
In processing phase use a CompositeItemProcessor
to pass InvalidLine
objects through a custom ItemProcessor
and do what do you prefer. 在处理阶段,使用CompositeItemProcessor
通过自定义ItemProcessor
传递InvalidLine
对象,然后执行您喜欢的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.