【问题标题】:Spring batch: handle subclassesSpring批处理:处理子类
【发布时间】:2019-01-30 17:29:00
【问题描述】:

假设我有 Event 类和 Event 类的 10 个子类(SubEvent1、SubEvent2... 等等)。我已经为 Spring Batch ItemReaderItemProcessorItemWriter 进行了配置。

我的项目处理器看起来像:

ItemProcessor<Event, Outputclass> {
 OutputClass process(Event e) {
   if(e instancof SubEvent1) {
     return processSubEvent1(e);
   } else if(e instanceof SubEvent2) {
     return processSubEvent2(e);
   } else ...
}

是否可以避免这些 instanceof 并由特定于类的处理器处理它?

【问题讨论】:

    标签: spring-batch


    【解决方案1】:

    您应该能够使用以下组合来做到这一点:

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      相关资源
      最近更新 更多