gpt4 book ai didi

java - RepositoryItemReader : java. util.ArrayList 无法转换为 org.springframework.data.domain.Page

转载 作者:行者123 更新时间:2023-11-30 06:05:48 26 4
gpt4 key购买 nike

我正在 Spring 批处理步骤中为阅读器设置一个 ItemRepositoryReader。我想使用 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);


}

关于java - RepositoryItemReader : java. util.ArrayList 无法转换为 org.springframework.data.domain.Page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45671742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com