当前位置:网站首页>Product name fuzzy search:
Product name fuzzy search:
2022-07-27 18:50:00 【Fantasia of the cat】
Process analysis :

Interface development :
Fuzzy query
sql:(productMapper)
/**
* Fuzzy search for product information based on keywords
* @param keyword
* @param start
* @param limit
* @return
*/
public List<ProductVO> selectProductByKeyword(@Param("kw") String keyword,
@Param("start") int start,
@Param("limit") int limit);The mapping file :
<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 Realization :
public R searchProduct(String kw,int pageNum,int limit);@Override
public R searchProduct(String kw, int pageNum, int limit) {
//1. Query search results
kw = "%"+kw+"%";
int start = (pageNum - 1)*limit;
List<ProductVO> productVOS = productMapper.selectProductByKeyword(kw, start, limit);
//2. Total number of records queried
Example example = new Example(Product.class);
Example.Criteria criteria = example.createCriteria();
criteria.andLike("productName",kw);
int count = productMapper.selectCountByExample(example);
//3. Calculate the total number of records
int pageCount = count%limit==0? count/limit:count/limit+1;
//4. encapsulation , Return the data
PageHelper<ProductVO> pageHelper = new PageHelper<>(count,pageCount,productVOS);
R r = new R(ResStatus.OK,"success",pageHelper);
return r;
}controller Realization :
// Query commodity interface by keyword
@GetMapping("/listbykeyword")
public R searchProducts(String keyword,int pageNum,int pageSize){
return productService.searchProduct(keyword, pageNum, pageSize);
}Query the brand of the corresponding product according to the keyword :
sql:

Database implementation :productMapper:
/**
* Query the brand list of related products according to the search keywords
* @param kw
* @return
*/
public List<String> selectBrandByKeyword(String kw);The mapping file :
<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 Realization :
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 Realization :
// Query the commodity brand interface according to keywords
@GetMapping("/listbrandsByKeyword")
public R getBrandsByKeyword(String keyword){
return productService.listBrandsByKeyword(keyword);
}边栏推荐
- Quick access to website media resources
- 2021.8.1 Notes database design
- 网红RGB镜子灯触摸芯片-DLT8S15B-杰力科创
- Wechat applet obtains openid, sessionkey, unionid
- MySQL 主从复制数据不一致,怎么办?
- Uni app for wechat login (to be finished)
- was not registered for synchronization because synchronization is not active[已解决]
- The combination of text and words perfectly explains the implementation process of MySQL logical backup
- 飞机大战敌机出场
- JS tool - Cookie simple encapsulation
猜你喜欢

Quick access to website media resources

2021.8.9 note request

2021.8.1 notes DBA

商品评论信息与评论信息分类

Log4j epic loopholes, big companies like jd.com have been recruited

你有没有在MySQL的order by上栽过跟头

The song of the virtual idol was originally generated in this way!

Must the MySQL query column be consistent with the group by field?

Uploading and downloading of files

百度地图技术概述,及基本API与WebApi的应用开发
随机推荐
pygame飞机大战游戏背景实现
2021.7.17 notes MySQL other commands
Use ETL tools for data migration in salesforce project
全自动吸奶器芯片-DLTAP703SD
Was not registered for synchronization because synchronization is not active[resolved]
Uniapp H5 cross domain problem
Hbuilder submission code
js实现简易表单验证与全选功能
你想得到想不到的MySQL面试题都在这了(2022最新版)
微信支付及支付回调
Must the MySQL query column be consistent with the group by field?
Wechat applet obtains openid, sessionkey, unionid
Generate PDM file from Navicat export table
多功能无线遥控艾灸仪芯片-DLTAP703SD
机器学习——SVM训练集只有一类标签数据而引发的错误
Solve the problem of JSP cascading
js中的函数与DOM获取元素和事件属性的使用
虚拟偶像的歌声原来是这样生成的!
MySQL basic statement
Zhaoqi scientific and technological innovation introduces high-level talents at home and abroad and connects innovation and entrepreneurship projects