首页 > 解决方案 > findAllByTimeStampBetweenAndStoreIn(Long startTime, Long endTime, List商店)不工作

问题描述

我正在尝试从给定的 timeStamp 和给定的商店列表中获取数据Elastic Index,但是当我通过遍历 listOfStores 来完成它时,它工作正常,我正在获取该特定的数据store

 listOfStores.forEach( i -> {
            List<InStoreDemographicIndex> inStoreDemographicIndices =
                inStoreSearchRepo.findAllByTimeStampBetweenAndStore(startTime, endTime, i)); 
}) 

但在我努力的同时,

List<InStoreDemographicIndex> inStoreDemographicIndices = inStoreSearchRepo
.findAllByTimeStampBetweenAndStoreIn(startTime, endTime, listOfStores);

一次只传递一个商店,这个查询不起作用,结果我得到了所有商店的数据,即使我只传递一个商店。

标签: spring-bootspring-data-jpa

解决方案


嗯,找了好久才得到这个问题的答案,终于在spring data ElasticSearch下得到了我的答案8.2.2 Query creation

在此处输入图像描述

Store由于存储库方法中使用的变量,上述查询不起作用,

In Service Class:

列出 inStoreDemographicIndices = inStoreSearchRepo .findAllByTimeStampBetweenAndStoreIn(startTime, endTime, listOfStores);

OLD inStoreSearchRepo Repository:

List<InStoreDemographicIndex> findAllByTimeStampBetweenAndStoreIn(Long startTime, Long endTime,  List<String> Store);

而不是 Store in 应该是商店。

Correct inStoreSearchRepo Repository:

findAllByTimeStampBetweenAndStoreIn(Long startTime, Long endTime, List stores);

所以总而言之:

假设如果字段名称是store,

您的存储库方法应该是List<Object> findAllByStoreIn(List<String> stores);

谢谢..!!


推荐阅读