SELECT * FROM USER WHERE username LIKE "%XX%';
在执行模糊查询的时候,需要对传入字段进行 拼接。推荐的方法是
SELECT * FROM TNotific
<where>
<if test="method != null">
and Method like CONCAT('%', #{method ,jdbcType=VARCHAR}, '%')
</if>
<if test="statusOfread != null">
and StatusOfread = #{statusOfread,jdbcType=VARCHAR}
</if>
<if test="bizCaseId != null">
and BizCaseId = #{bizCaseId,jdbcType=VARCHAR}
</if>
</where>
String statusOfread = "0"; | String method = "U"; | String bizCaseId = null; |
0(String) | U(String) |
SQL 执行结果是
SELECT * FROM TNotific WHERE Method like CONCAT('%', ?, '%') and StatusOfread = ?