最新下载
热门教程
- 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}
相关文章
- steam怪物猎人和switch哪个好 03-23
- 辐射4 老滚5哪个好玩 03-23
- 漫蛙官方入口-Manwa2全新上线 03-23
- 拳皇97是哪个游戏公司 03-23
- 灵境余晖下载教程-灵境余晖预约通道及2026资讯 03-23
- 秋蝉韩漫免费阅读入口-秋蝉漫画无删减版在线观看链接 03-23