Merge remote-tracking branch 'origin/master'

master
Aokiso 7 years ago
commit bce56c4e60

@ -7,11 +7,20 @@ import java.util.List;
@Mapper @Mapper
public interface productMapper { 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}") @Select("select * from product where productNum = #{productNum}")
public Product selectProductByProductNum(long productNum); public Product selectProductByProductNum(long productNum);
@Select("select * from product where productName = #{productName}") @Select("select * from product where productName = #{productName}")
public Product selectProductByProductName(long productName); public Product selectProductByProductName(String productName);
@Select("select * from product") @Select("select * from product")
public List<Product> select(); public List<Product> select();

@ -14,6 +14,9 @@ public interface usageDateMapper {
@Select("select * from usagedate") @Select("select * from usagedate")
public List<UsageDate> select(); 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," + @Insert("insert into usagedate(checkNum, productNum, userNum," +
" bankAccount, bankNum, year, amount, startTime)" + " bankAccount, bankNum, year, amount, startTime)" +
" values (#{checkNum},#{productNum},#{userNum},#{bankAccount},#{bankNum}," + " values (#{checkNum},#{productNum},#{userNum},#{bankAccount},#{bankNum}," +

@ -25,7 +25,7 @@ public class addController extends HttpServlet {
product.setProductDescription(request.getParameter("description")); product.setProductDescription(request.getParameter("description"));
product.setPictureAddress(request.getParameter("address")); product.setPictureAddress(request.getParameter("address"));
int result= addPro.add(product); int result= addPro.add(product);
response.setContentType("text/hmtl;charset=utf-8"); response.setContentType("text/html;charset=utf-8");
writer=response.getWriter(); writer=response.getWriter();
if(result==1){ if(result==1){
writer.write("增加成功"); writer.write("增加成功");

@ -1,17 +1,38 @@
package com.example.demo.searchService.controller; package com.example.demo.searchService.controller;
import com.example.demo.bean.Product; import com.example.demo.bean.Product;
import com.example.demo.searchService.service.impl.ProductSearchServiceImpl; import com.example.demo.searchService.service.ProductSearchService;
import org.junit.runner.Request; 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; import java.util.List;
@Controller
public class SearchServiceController { public class SearchServiceController {
ProductSearchServiceImpl productSearchService = new ProductSearchServiceImpl(); private ProductSearchService productSearchService;
//模糊查询 @RequestMapping("/search")
@GetMapping("/findByNameLike/{productName}") public List<Product> productSearch(HttpServletRequest request, HttpServletResponse response){
public List<Product> findByNameLike(@PathVariable(value = "productName") String productName){ List<Product> list = new ArrayList<Product>();
return productSearchService.findByNameLike(productName); 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;
} }
} }

@ -1,15 +0,0 @@
package com.example.demo.searchService.repository;
import com.example.demo.bean.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface ProductRepository extends JpaRepository<Product,Integer>, JpaSpecificationExecutor<Product> {
@Query("select p.productName from Product p where p.productName like CONCAT('%',:productName,'%')")
List<Product> findByNameLike(@Param("productName") String productName);
}

@ -6,4 +6,10 @@ import java.util.List;
public interface ProductSearchService { public interface ProductSearchService {
List<Product> findByNameLike(String productName); List<Product> findByNameLike(String productName);
List<Product> findByCategory(String category);
List<Product> findByIntrate(float intrate);
List<Product> findByCount();
} }

@ -1,171 +1,44 @@
package com.example.demo.searchService.service.impl; 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.bean.Product;
import com.example.demo.searchService.repository.ProductRepository;
import com.example.demo.searchService.service.ProductSearchService; import com.example.demo.searchService.service.ProductSearchService;
import org.springframework.data.domain.Example; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
public class ProductSearchServiceImpl implements ProductSearchService { public class ProductSearchServiceImpl implements ProductSearchService {
ProductRepository productRepository = new ProductRepository() { @Autowired
productMapper productMapper;
usageDateMapper usageDateMapper;
Product product;
@Override @Override
public List<Product> findByNameLike(String productName){ public List<Product> findByNameLike(String productName){
return null; return productMapper.findByNameLike(productName);
} }
@Override @Override
public List<Product> findAll() { public List<Product> findByCategory(String category){
return null; return productMapper.findByCategory(category);
} }
@Override @Override
public List<Product> findAll(Sort sort) { public List<Product> findByIntrate(float intrate){
return null; return productMapper.findByIntrate(intrate);
} }
@Override @Override
public List<Product> findAllById(Iterable<Integer> iterable) { public List<Product> findByCount(){
return null; 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;
@Override
public <S extends Product> List<S> saveAll(Iterable<S> iterable) {
return null;
}
@Override
public void flush() {
}
@Override
public <S extends Product> S saveAndFlush(S s) {
return null;
}
@Override
public void deleteInBatch(Iterable<Product> iterable) {
}
@Override
public void deleteAllInBatch() {
} }
@Override
public Product getOne(Integer integer) {
return null;
}
@Override
public <S extends Product> List<S> findAll(Example<S> example) {
return null;
}
@Override
public <S extends Product> List<S> findAll(Example<S> example, Sort sort) {
return null;
}
@Override
public Optional<Product> findOne(Specification<Product> specification) {
return Optional.empty();
}
@Override
public List<Product> findAll(Specification<Product> specification) {
return null;
}
@Override
public Page<Product> findAll(Specification<Product> specification, Pageable pageable) {
return null;
}
@Override
public List<Product> findAll(Specification<Product> specification, Sort sort) {
return null;
}
@Override
public long count(Specification<Product> specification) {
return 0;
}
@Override
public Page<Product> findAll(Pageable pageable) {
return null;
}
@Override
public <S extends Product> S save(S s) {
return null;
}
@Override
public Optional<Product> findById(Integer integer) {
return Optional.empty();
}
@Override
public boolean existsById(Integer integer) {
return false;
}
@Override
public long count() {
return 0;
}
@Override
public void deleteById(Integer integer) {
}
@Override
public void delete(Product product) {
}
@Override
public void deleteAll(Iterable<? extends Product> iterable) {
}
@Override
public void deleteAll() {
}
@Override
public <S extends Product> Optional<S> findOne(Example<S> example) {
return Optional.empty();
}
@Override
public <S extends Product> Page<S> findAll(Example<S> example, Pageable pageable) {
return null;
}
@Override
public <S extends Product> long count(Example<S> example) {
return 0;
}
@Override
public <S extends Product> boolean exists(Example<S> example) {
return false;
}
};
public List<Product> findByNameLike(String productName){
List<Product> list = productRepository.findByNameLike(productName);
return list;
}
} }

Loading…
Cancel
Save