我在 Spring 批处理步骤中为阅读器设置了ItemRepositoryReader。我想使用带有两个参数min和max的findByScenarioBetween方法。

我的回购

public interface FuneralPricingRepository extends JpaRepository<FuneralPricing, Long> {

    @Query("select p from FuneralPricing p where p.scenario between ?1 and ?2")
    List<FuneralPricing> findByScenarioBetween(Long min, Long max, Pageable pageable);


}

我的读者
  @Bean
  @StepScope
  public ItemReader<FuneralPricing> funeralPricingRepositoryReader(
          @Value("#{jobParameters[start]}") Long start,
          @Value("#{jobParameters[end]}") Long end) {
    RepositoryItemReader<FuneralPricing> repositoryItemReader = new RepositoryItemReader<>();
    repositoryItemReader.setPageSize(10);
    repositoryItemReader.setSort(funeralPricingSort());
    repositoryItemReader.setRepository(funeralPricingRepository);
    repositoryItemReader.setMaxItemCount(100);
    repositoryItemReader.setMethodName("findByScenarioBetween");
    List parameters = new ArrayList();
    parameters.add(start);
    parameters.add(end);
    repositoryItemReader.setArguments(parameters);
    return repositoryItemReader;
  }

当我使用findAll时,它工作正常。但是,我不想每次都阅读所有行。我不知道我的阅读器是否缺少任何内容!,谢谢。
java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.springframework.data.domain.Page at org.springframework.batch.item.data.RepositoryItemReader.doPageRead(RepositoryItemReader.java:208) at org.springframework.batch.item.data.RepositoryItemReader.doRead(RepositoryItemReader.java:153) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) at com.sun.proxy.$Proxy120.read(Unknown Source) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) at org.sp

最佳答案

List<FuneralPricing>更新为Page<FuneralPricing>

public interface FuneralPricingRepository extends JpaRepository<FuneralPricing, Long> {


    Page<FuneralPricing> findByScenarioBetween(Long min, Long max, Pageable pageable);


}

10-07 20:47