按关键字查询,产品使用热度查询,利率高低排序,按类别查询。

master
istars 7 years ago
parent 1967ee0224
commit a2a3052ac9

@ -7,11 +7,21 @@ import java.util.List;
@Mapper
public interface productMapper {
@Select("select * from product where productName like '%#{productName}%'")
public List<Product> findByNameLike(String productName);
@Select("select * from product where productName = #{category}")
public List<Product> findByCategory(String category);
@Select("select * from product where intrate = #{intrate} order by intrate ASC")
public List<Product> findByIntrate(float intrate);
@Select("select * from product where productNum = #{productNum}")
public Product selectProductByProductNum(long productNum);
@Select("select * from product where productName = #{productName}")
public Product selectProductByProductName(long productName);
public Product selectProductByProductName(String productName);
@Select("select * from product")
public List<Product> select();

@ -14,6 +14,10 @@ public interface usageDateMapper {
@Select("select * from usagedate")
public List<UsageDate> select();
@Select("select productNum from usageDate group by productNum order by count(productNum) DESC")
public List<Integer> selectByCount();
@Insert("insert into usagedate(checkNum, productNum, userNum," +
" bankAccount, bankNum, year, amount, startTime)" +
" values (#{checkNum},#{productNum},#{userNum},#{bankAccount},#{bankNum}," +

@ -0,0 +1,38 @@
package com.example.demo.searchService.controller;
import com.example.demo.bean.Product;
import com.example.demo.searchService.service.ProductSearchService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@Controller
public class SearchServiceController {
private ProductSearchService productSearchService;
@RequestMapping("/search")
public List<Product> productSearch(HttpServletRequest request, HttpServletResponse response){
List<Product> list = new ArrayList<Product>();
String productName = request.getParameter("productName");
String category = request.getParameter("category");
float intrate = Integer.parseInt(request.getParameter("intrate"));
if(productName!=null){
list = productSearchService.findByNameLike(productName);
//按关键字搜索
}else if(category!=null){
list = productSearchService.findByCategory(category);
//按产品类别搜索
}else if(intrate!=0){
list = productSearchService.findByIntrate(intrate);
//按利率排序由低到高
}else{
list = productSearchService.findByCount();
//默认按产品使用的产品的数量由高到低排序
}
return list;
}
}

@ -0,0 +1,19 @@
package com.example.demo.searchService.service;
import com.example.demo.bean.Product;
import java.util.List;
public interface ProductSearchService {
//按关键字查询
List<Product> findByNameLike(String productName);
//按类别查询
List<Product> findByCategory(String category);
//按利率从高到低
List<Product> findByIntrate(float intrate);
////默认按产品使用的产品的数量由高到低排序
List<Product> findByCount();
}

@ -0,0 +1,45 @@
package com.example.demo.searchService.service.impl;
import com.example.demo.Dao.productMapper;
import com.example.demo.Dao.usageDateMapper;
import com.example.demo.bean.Product;
import com.example.demo.searchService.service.ProductSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
public class ProductSearchServiceImpl implements ProductSearchService {
@Autowired
productMapper productMapper;
usageDateMapper usageDateMapper;
Product product;
@Override
public List<Product> findByNameLike(String productName){
return productMapper.findByNameLike(productName);
}
@Override
public List<Product> findByCategory(String category){
return productMapper.findByCategory(category);
}
@Override
public List<Product> findByIntrate(float intrate){
return productMapper.findByIntrate(intrate);
}
@Override
public List<Product> findByCount(){
List<Product> productList = new ArrayList<Product>();
List<Integer> listusage = usageDateMapper.selectByCount();
int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray();
for(int i=0;i<arr.length;i++){
product = productMapper.selectProductByProductNum(arr[i]);
productList.add(product);
}
return productList;
}
}
Loading…
Cancel
Save