栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > Java

【Mybatis+springBoot】实现模糊查询

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Mybatis+springBoot】实现模糊查询

【Mybatis+springBoot】实现模糊查询
    • pojo
    • 数据库
    • Mapper接口类
    • Service
    • ServiceImpl
    • Mapper.xml配置文件
    • Controller
    • 测试
    • 参考资料

       今天写项目,设计到了模糊查询,模糊查询部分学习时间长,都又忘记了,今天回顾了一下,于是这里写个总结。

pojo
package com.yczxyy.paperfree.dto.jhemr;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


@Data
public class JobEmrMonitor {
    @ApiModelProperty(value = "监控代码编号")
    private String MONITOR_ITEM_CODE;
    @ApiModelProperty(value = "监控代码名称")
    private String MONITOR_ITEM_NAME;
}
数据库

Mapper接口类
  
    List getMonitor(String MONITOR_ITEM_NAME);
Service
List getMonitor(String MONITOR_ITEM_NAME);
ServiceImpl
  @Override
    public List getMonitor(String MONITOR_ITEM_NAME) {
        return dmsZhiKongRuleDao.getMonitor(MONITOR_ITEM_NAME);
    }
Mapper.xml配置文件
   
        select MONITOR_ITEM_CODE MONITOR_ITEM_CODE,
               MONITOR_ITEM_NAME MONITOR_ITEM_NAME
        from dms_monitor
        where 1=1
        
        and MONITOR_ITEM_NAME like concat('%',#{MONITOR_ITEM_NAME},'%')
        

在此 SQL 语句中, where 1=1 是多条件拼接时的小技巧, 后面的条件查询就可以都用 and 了。

Controller
@ApiOperation("监控代码/名称 字典")
@PostMapping("getMonitorNameAndCode")
public CommonResult getMonitorNameAndCode(@RequestParam(value="MONITOR_ITEM_NAME", required = false) String MONITOR_ITEM_NAME){
    ArrayList list = new ArrayList<>();
    list=(ArrayList) dmsZhiKongRuleService.getMonitor(MONITOR_ITEM_NAME);
    return CommonResult.success(list);

}
测试

参考资料

1、https://blog.csdn.net/Rice_kil/article/details/83622160
2、https://blog.csdn.net/m0_48814545/article/details/116569516
3、https://blog.csdn.net/fanminghao/article/details/107544056
4、https://blog.csdn.net/qq_43700885/article/details/104148421

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/1036752.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号