当前位置:网站首页>商品名称模糊搜索:
商品名称模糊搜索:
2022-07-27 16:18:00 【猫的幻想曲】
流程分析 :

接口开发:
模糊查询
sql:(productMapper)
/**
* 根据关键字模糊搜索商品信息
* @param keyword
* @param start
* @param limit
* @return
*/
public List<ProductVO> selectProductByKeyword(@Param("kw") String keyword,
@Param("start") int start,
@Param("limit") int limit);映射文件:
<select id="selectProductByKeyword" resultMap="ProductVOMap2">
select product_id,
product_name,
category_id,
root_category_id,
sold_num,
product_status,
content,
create_time,
update_time
from product
where product_name like #{kw}
limit #{start},#{limit}
</select>service实现:
public R searchProduct(String kw,int pageNum,int limit);@Override
public R searchProduct(String kw, int pageNum, int limit) {
//1.查询搜索结果
kw = "%"+kw+"%";
int start = (pageNum - 1)*limit;
List<ProductVO> productVOS = productMapper.selectProductByKeyword(kw, start, limit);
//2.查询总记录数
Example example = new Example(Product.class);
Example.Criteria criteria = example.createCriteria();
criteria.andLike("productName",kw);
int count = productMapper.selectCountByExample(example);
//3.计算总记录数
int pageCount = count%limit==0? count/limit:count/limit+1;
//4.封装,返回数据
PageHelper<ProductVO> pageHelper = new PageHelper<>(count,pageCount,productVOS);
R r = new R(ResStatus.OK,"success",pageHelper);
return r;
}controller实现:
//根据关键字查询商品接口
@GetMapping("/listbykeyword")
public R searchProducts(String keyword,int pageNum,int pageSize){
return productService.searchProduct(keyword, pageNum, pageSize);
}根据关键字查询对应商品的品牌:
sql:

数据库实现:productMapper:
/**
* 根据搜索关键字查询相关商品的品牌列表
* @param kw
* @return
*/
public List<String> selectBrandByKeyword(String kw);映射文件:
<select id="selectBrandByKeyword" resultSets="java.util.List" resultType="String">
select Distinct brand
from product_params
where product_id in (
select product_id
from product
where product_name like #{kw}
)
</select>service实现:
public R listBrandsByKeyword(String kw);@Override
public R listBrandsByKeyword(String kw) {
kw = "%"+kw+"%";
List<String> strings = productMapper.selectBrandByKeyword(kw);
return new R(ResStatus.OK,"success",strings);
}controller实现:
//根据关键字查询商品品牌接口
@GetMapping("/listbrandsByKeyword")
public R getBrandsByKeyword(String keyword){
return productService.listBrandsByKeyword(keyword);
}边栏推荐
- was not registered for synchronization because synchronization is not active[已解决]
- Why don't you like it? It's easy to send mail in ci/cd
- 阿里p8总结的10条 SQL 优化方案(非常实用)
- 音乐律动七彩渐变灯芯片--DLT8S04A-杰力科创
- 如何实现Word、PDF、TXT文件的全文内容检索?
- The song of the virtual idol was originally generated in this way!
- 家用静音驱蚊灯芯片-DLTAP703SD-杰力科创
- [yuntu said] 249 mobile application security service - app's physical examination center, comprehensive testing, safe on the road!
- js中的函数与DOM获取元素和事件属性的使用
- 修改input中placeholder样式
猜你喜欢

Build a simple knowledge question and answer system

10 SQL optimization schemes summarized by Alibaba P8 (very practical)

Complete set of machine learning classification task effect evaluation indicators (including ROC and AUC)

Error launching IDEA

Let's move forward together, the 10th anniversary of Google play!

Uni app label jump

How to realize the full-text content retrieval of word, PDF and txt files?

LED带风扇护眼学习台灯触摸芯片-DLT8S12A

mysql视图基本操作

Uni app form submit button send request
随机推荐
[mit 6.s081] LEC 9: interrupts notes
File path read
RSA encryption and decryption (compatible with wechat applet environment)
filebeat.yml配置文件关于多个服务的配置问题
Log4j epic loopholes, big companies like jd.com have been recruited
Use mobaxtermto establish a two-tier springboard connection
MySQL learns the relationship between Day2 Sorting Query / aggregation function / grouping query / paging query / constraint / multiple tables
2021.8.1 notes DBA
Labels such as {@code}, {@link} and < P > in the notes
内网的公司邮箱服务器怎么发外部邮件
JS中的数组与对象
A case to understand MySQL view
JS to achieve smooth scrolling of pages or DOM elements
I was forced to optimize the API gateway query interface
[mit 6.s081] LEC 6: isolation & system call entry/exit notes
2021.8.6 notes jsoup
MySQL set validate_ Adding skip grant tables after password=off failed to start the service
搭建一个简单的知识问答系统
2021.7.31 note view
2021.8.7笔记 servlet