escape:指定某字符为特殊字符:
例如指定‘\’ 为特殊字符
java:
例如:select * from t_event t where t.eventname like '%\%%' escape '\'
select * from t_event t where t.eventname like '%+escapeForDaoLike("%")+%' escape '\'即可
例如指定‘\’ 为特殊字符
java:
/**
* 将dao中使用like的时候将内容转义,可以转义'\','%','_'
*
* @param content 转义前的字符串
* @return String 转义后的字符串
*/
public static String escapeForDaoLike(String content)
{
// 转义前的字符串不为空,执行替换操作
if (isNotEmpty(content))
{
content = content.replace("\\", "\\\\");
content = content.replace("%", "\\%");
content = content.replace("_", "\\_");
return content;
}
// 为空,返回空串
else
{
return "";
}
}
例如:select * from t_event t where t.eventname like '%\%%' escape '\'
select * from t_event t where t.eventname like '%+escapeForDaoLike("%")+%' escape '\'即可