Spring batch Spring批处理:句柄子类
让我们假设我有一个类Event,其中包含Event和类Event的10个子类(SubEvent1,SubEvent2…等等)。我已经为spring批处理项目阅读器、项目处理器和项目编写器进行了配置 我的项目处理器看起来像:Spring batch Spring批处理:句柄子类,spring-batch,Spring Batch,让我们假设我有一个类Event,其中包含Event和类Event的10个子类(SubEvent1,SubEvent2…等等)。我已经为spring批处理项目阅读器、项目处理器和项目编写器进行了配置 我的项目处理器看起来像: ItemProcessor<Event, Outputclass> { OutputClass process(Event e) { if(e instancof SubEvent1) { return processSubEvent1(e);
ItemProcessor<Event, Outputclass> {
OutputClass process(Event e) {
if(e instancof SubEvent1) {
return processSubEvent1(e);
} else if(e instanceof SubEvent2) {
return processSubEvent2(e);
} else ...
}
ItemProcessor{
OutputClass进程(事件e){
if(e instancof SubEvent1){
返回进程子事件1(e);
}else if(子事件2的实例){
返回进程子事件2(e);
}否则。。。
}
是否可以避免这些实例,并使用特定于类的处理器进行处理?您应该能够使用以下组合来实现这一点:
- :使用相应的
ItemProcessor
- :根据项目的子类型对项目进行分类