Browse Source

Merge branch 'master' of https://gogs.seec.seecoder.cn/DingXiaoYu/BlueWhale

Gudge-ZL 2 years ago
parent
commit
88e9bd795e

+ 9 - 3
src/main/java/com/seecoder/BlueWhale/serviceImpl/ProductServiceImpl.java

@@ -84,9 +84,15 @@ public class ProductServiceImpl implements ProductService {
             condition=condition.concat("AND price <= :price");
         }
         Query query=entityManager.createQuery(condition);
-        query.setParameter("name",name);
-        query.setParameter("category",category);
-        query.setParameter("price",price);
+        if (name!=null && name.length()>0){
+            query.setParameter("name",name);
+        }
+        if (category!=null){
+            query.setParameter("category",category);
+        }
+        if (price!=null && price>0){
+            query.setParameter("price",price);
+        }
         List<Product> products=query.getResultList();
         return products.stream().map(Product::toVO).collect(Collectors.toList());
     }