最新下载
热门教程
- 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}
相关文章
- 三国志8重制版虚构特典剧本介绍说明 10-30
- 暗喻幻想暗黑法师解锁方法攻略分享 10-30
- 暗喻幻想元素大师解锁方法攻略分享 10-30
- 暗喻幻想地下纳骨堂锁住的门打开方法 10-30
- 暗喻幻想6月22日玛丽亚位置一览 10-30
- 暗喻幻想巫师阿基态解锁方法分享 10-30