时间:2022-12-27 10:18:34 | 栏目:JAVA代码 | 点击:次
针对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; }
并调用工具类处理
String areaname = request.getParameter("Areaname"); if (areaname != null) { if ("".equals(areaname)) { areaname = null; } else { areaname = StringUtils.escapeStr(areaname); } }
<if test="param.areaname!=null"> and areaname like '%'||#{param.areaname}||'%' escape '\'</if>
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}