1.入参的时候,就直接将“%%”拼接上,
mapParam.put("cgropName", "%"+cgropName+"%");
<if test="cgropName != null and cgropName != ''">
AND A.CGROP_NAME LIKE #{cgropName}
</if>
2.bind标签
bind 元素可以从 OGNL 表达式中创建一个变量并将其绑定到上下文。比如:
<select id="selectBlogsLike" resultType="Blog"> <bind name="pattern" value="'%' + _parameter.getTitle() + '%'" /> SELECT * FROM BLOG WHERE title LIKE #{pattern} </select>
3.CONCAT
where username LIKE concat(concat('%',#{username}),'%')
4.MyBatis常用OGNL表达式 @class@method(args)
调用类的静态方法
<if test="deleteIds != 'all'">
AND to_char(ID) IN ${@com.cqmc.cqiop.portal.util.Ognl@loadLikeSql(deleteIds)}
</if>;
public static String loadLikeSql(String str) throws Exception{
if(str==null || str.isEmpty() ){
throw new Exception("入参是错误的");
}
return "'%" + str + "%'";
}