Mybatis解決sql中like通配符模糊匹配


偶爾用一次like進行模糊查詢,
除了%,竟忘了還有別的通配符。。
被人提了bug。

處理字符串中的通配符-----前面放一個轉義符

	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;
	}

sql 中 也要作以下處理

<if test="param.areaname!=null"> and areaname like '%'||#{param.areaname}||'%' escape '\'</if>

原文是轉的,卻不見原文的原文地址。
https://blog.csdn.net/w522301629/article/details/82379514


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM