1、条件查询时,不指定jdbcType=VARCHAR,若入参是0012346595时将查不到数据。
<if test="filmCode != null and filmCode != ''">
and f.film_code= #{filmCode}
</if>
原因:当不指定jdbcType为字符串时,字符串0012346595将会被转换为数值12346595,导致查不到数据。
正确方式是:
<if test="filmCode != null and filmCode != ''">
and f.film_code= #{filmCode,jdbcType=VARCHAR}
</if>
这样字符串0012346595就不会被转换为数值了。
2、在if使用字符串数字,如果直接写<if test = "xx == '1' "> </if>
,这样即使是xx == ‘1’
,通常情况下也不会进入判断的。因为字符串'1'
被转换成了数字1
。必须这样写:xx == 1
。不推荐这样写,更规范的写法是,使用toString()
转换成字符串
<select id="getByNameAndPwd" parameterType="String" resultMap="MemberResult">
select
*
from `member`
<if test="isMerch != '' and isMerch == '1'.toString() " >
where `mobile` = #{name}
and `password` = #{password}
</if>
<if test="isMerch != '' and isMerch == '2'.toString() " >
where `name` = #{name}
and `password` = #{password}
</if>
</select>