一、使用mybatis的bind标签
<if test="name != null and name != ''">
<bind name="nameLike" value="'%' + name+ '%'"/>
AND NAME LIKE #{nameLike}
</if>
很好的方法,不用担心数据库不一致以及SQL注入的问题
二、使用${}
<if test="name != null and name != ''">
AND NAME LIKE '%${name}%'
</if>
注意:此方法会存在SQL注入的隐患
三、CONCAT函数(适用于MYSQL数据库查询)
<if test="name != null and name != ''">
AND NAME LIKE CONCAT('%',#{name},'%')
</if>
注意:oracle的concat函数只能有两个参数,无法做前后模糊查询
四、|| 拼接(适用于ORACLE数据库查询)
<if test="name != null and name != ''">
AND NAME LIKE '%'||#{name}||'%'
</if>