|
|
@@ -85,19 +85,20 @@ public class ProductServiceImpl implements ProductService {
|
|
|
public List<ProductVO> getProductsWithCondition(String name, CategoryEnum category, Double price) {
|
|
|
String condition="SELECT p FROM Product p WHERE 1=1";
|
|
|
if (name!=null && name.length()>0){
|
|
|
- condition=condition.concat(" AND name = :name");
|
|
|
+ condition=condition.concat("AND name LIKE :name");
|
|
|
+
|
|
|
}
|
|
|
- if (category!=null){
|
|
|
- condition=condition.concat(" AND category = :category");
|
|
|
+ if (category!=CategoryEnum.ALL){
|
|
|
+ condition = condition.concat(" AND category = :category");
|
|
|
}
|
|
|
if (price!=null && price>0){
|
|
|
condition=condition.concat(" AND price <= :price");
|
|
|
}
|
|
|
Query query=entityManager.createQuery(condition);
|
|
|
if (name!=null && name.length()>0){
|
|
|
- query.setParameter("name",name);
|
|
|
+ query.setParameter("name","%" + name + "%");
|
|
|
}
|
|
|
- if (category!=null){
|
|
|
+ if (category!=CategoryEnum.ALL){
|
|
|
query.setParameter("category",category);
|
|
|
}
|
|
|
if (price!=null && price>0){
|