where 元素只会在至少有一个子元素的条件返回 SQL 子句的情况下才去插入“WHERE”子句。而且,若语句的开头为“AND”或“OR”,where 元素也会将它们去除。
SELECT * FROM TNotific
<where>
<if test="method != null">
and Method = #{method,jdbcType=VARCHAR}
</if>
<if test="statusOfread != null">
and StatusOfread = #{statusOfread,jdbcType=VARCHAR}
</if>
</where>
入参
String statusOfread = "0"; | String method = "PUT"; |
SQL执行语句
SELECT * FROM TNotific WHERE Method = ? and StatusOfread = ? |
入参
String statusOfread = null; | String method = "PUT"; |
SQL执行语句
SELECT * FROM TNotific WHERE Method = ? |
入参
String statusOfread = null; | String method = null; |
SQL执行语句
SELECT * FROM TNotific |