Mybatis如何解决sql中like通配符模糊匹配问题
作者:时间辜负了谁 时间:2023-12-22 19:39:52
sql中like通配符模糊匹配问题
针对oracle数据库:
将查询条件通过功能类处理
/**
* Description: 处理转义字符%和_,针对ORACLE数据库
*
* @param str
* @return
*/
public static String escapeStr(String str) {
String temp = "";
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '%' || str.charAt(i) == '_') {
temp += "\\" + str.charAt(i);
} else {
temp += str.charAt(i);
}
}
return temp;
}
后台Contronller获得查询条件
并调用工具类处理
String areaname = request.getParameter("Areaname");
if (areaname != null) {
if ("".equals(areaname)) {
areaname = null;
} else {
areaname = StringUtils.escapeStr(areaname);
}
}
mapper.xml中对应的使用方法
<if test="param.areaname!=null"> and areaname like '%'||#{param.areaname}||'%' escape '\'</if>
使用like实现模糊匹配
方式一
select * from t_user where name like ' %${value}% '
方式二
select * from t_user where name like '%'||${value}||'%'
方式三
select * from t_user where name like #{do_it_in_java}
来源:https://blog.csdn.net/kpchen_0508/article/details/48496515
标签:Mybatis,sql,like,通配符,模糊匹配
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java如何在临界区中避免竞态条件
2022-11-02 09:39:29
C#实现一个控制台的点餐系统
2023-09-03 20:47:24
![](https://img.aspxhome.com/file/2023/1/113881_0s.jpg)
快速排序算法在Java中的实现
2022-05-25 01:06:15
![](https://img.aspxhome.com/file/2023/7/69317_0s.png)
教你开发脚手架集成Spring Boot Actuator监控的详细过程
2021-11-19 03:27:39
Java 转型(向上或向下转型)详解及简单实例
2021-10-17 14:29:27
Android中的Looper对象详细介绍
2023-02-26 08:33:39
android实现扫码枪功能
2022-08-28 21:33:35
Android 动态改变布局实例详解
2023-11-25 22:04:49
![](https://img.aspxhome.com/file/2023/6/96796_0s.png)
C语言数据结构之二叉树详解
2021-08-18 20:56:41
![](https://img.aspxhome.com/file/2023/3/120783_0s.png)
在Spring Boot2中使用CompletableFuture的方法教程
2022-09-27 14:18:51
Java查看线程运行状态的方法详解
2023-05-23 12:21:10
![](https://img.aspxhome.com/file/2023/4/79294_0s.png)
深入了解C#多线程安全
2023-08-08 19:43:32
![](https://img.aspxhome.com/file/2023/4/108784_0s.png)
关于RxJava的一些特殊用法小结
2022-06-13 13:31:54
Redis缓存,泛型集合与json字符串的相互转换实例
2021-07-18 16:57:15
![](https://img.aspxhome.com/file/2023/9/136629_0s.jpg)
Spring Data JPA框架快速入门之自定义Repository接口
2023-05-23 03:49:48
C#实现对二维数组排序的方法
2023-06-19 09:09:08
android 封装抓取网页信息的实例代码
2021-11-28 09:40:32
Java多线程run方法中直接调用service业务类应注意的问题及解决
2021-12-28 19:51:46
![](https://img.aspxhome.com/file/2023/0/92680_0s.png)
详解Kotlin和anko融合进行Android开发
2021-08-15 19:34:16
Android Studio中如何修改APP图标和APP名称
2023-04-04 17:02:10
![](https://img.aspxhome.com/file/2023/1/125361_0s.png)