最新下载
热门教程
- 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}
相关文章
- 新三国志曹操传赵云救公孙关卡攻略 07-02
- ps怎样给美女照片添加好看的蓝色美瞳效果? 07-02
- 区块链:Gate.io手机App快捷交易买币/卖币操作步骤教程 07-02
- 碳碳岛游戏玩法特色介绍说明 07-02
- 柴犬币(SHIB)价格预测:随着大额交易激增和下架担忧加剧,柴犬币能否复苏? - Brave New Coin 07-02
- 无畏契约炼狱源工重镇怎么守A 07-02