Selaa lähdekoodia

搜索功能查询结果为空问题修复

macro 2 vuotta sitten
vanhempi
commit
485aec3f31

+ 4 - 3
mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java

@@ -1,5 +1,6 @@
 package com.macro.mall.search.service.impl;
 
+import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.util.StrUtil;
 import com.macro.mall.search.dao.EsProductDao;
 import com.macro.mall.search.domain.EsProduct;
@@ -162,7 +163,7 @@ public class EsProductServiceImpl implements EsProductService {
         LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
         SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
         if(searchHits.getTotalHits()<=0){
-            return new PageImpl<>(null,pageable,0);
+            return new PageImpl<>(ListUtil.empty(),pageable,0);
         }
         List<EsProduct> searchProductList = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());
         return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits());
@@ -206,12 +207,12 @@ public class EsProductServiceImpl implements EsProductService {
             LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
             SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
             if(searchHits.getTotalHits()<=0){
-                return new PageImpl<>(null,pageable,0);
+                return new PageImpl<>(ListUtil.empty(),pageable,0);
             }
             List<EsProduct> searchProductList = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());
             return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits());
         }
-        return new PageImpl<>(null);
+        return new PageImpl<>(ListUtil.empty());
     }
 
     @Override