您的位置:首页 > 其它

mybatis中字符串数字

2019-05-24 08:51 316 查看

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: