当前位置:网站首页>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);
}边栏推荐
- Machine learning -- error caused by only one kind of label data in SVM training set
- 飞机大战碰撞检测
- 兆骑科创海内外引进高层次人才,创新创业项目对接
- Use mobaxtermto establish a two-tier springboard connection
- Jianmu continuous integration platform v2.5.2 release
- Wechat applet obtains mobile number
- 【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
- filebeat.yml配置文件关于多个服务的配置问题
- mysql视图基本操作
- 一个案例理解mysql视图
猜你喜欢

V-bind and V-for

Commodity comment information and comment information classification

微信支付及支付回调

Jianmu continuous integration platform v2.5.2 release

建木持续集成平台v2.5.2发布

连接查询和子查询

idea 2020.1社区版下载体验

百度地图技术概述,及基本API与WebApi的应用开发

Run the uniapp to the mobile phone (real machine debugging)

"MySQL things" explains the indexing principle in detail
随机推荐
How to send external mail to the company mailbox server on the Intranet
2021.7.19 notes DML
Mybtis-Plus常用的内置方法
电动加热护颈枕芯片-DLTAP703SC
Wechat applet obtains mobile number
org.gradle.api. UncheckedIOException: Could not load properties for module ‘gradle-kotlin-dsl‘ from C
阿里p8总结的10条 SQL 优化方案(非常实用)
[yuntu said] 249 mobile application security service - app's physical examination center, comprehensive testing, safe on the road!
Filebeat.yml configuration file about the configuration of multiple services
内网的公司邮箱服务器怎么发外部邮件
Mode= "widthfix" attribute in image tag
TS study notes class
Infrared hyperspectral survey
Idea 2020.1 Community Edition download experience
MySQL basic statement
订单的提交
Nacos display service registration address error
建木持续集成平台v2.5.2发布
Build a simple knowledge question and answer system
JS tool - Cookie simple encapsulation