mybatis中字符串数字

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>
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值