最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Mybatis解决sql中like通配符模糊匹配问题方法
时间:2022-06-29 01:57:44 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Mybatis解决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中对应的使用方法
and areaname like '%'||#{param.areaname}||'%' escape ''
使用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}
相关文章
- 百炼英雄怎么挂机 挂机方式及各等级最优点位攻略 12-15
- 百炼英雄vip礼包码大全 最新可用vip礼包码 12-15
- 光与影33号远征队符文收集:强力复生符文效果及获取方式详解 12-15
- 百炼英雄兑换码有哪些 最新可用兑换码及兑换方式 12-15
- 神器传说怎么克制闪避流 闪避流克制阵容实战攻略 12-15
- 神器传说怎么打异兽分最高 异兽冲榜高分搭配 12-15