使用mybatis时,若某个字段是纯数字字符串,不指定类型时引发的问题?

条件查询时,不指定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就不会被转换为数值了。

猜你喜欢

转载自blog.csdn.net/qq_42093488/article/details/80521984
今日推荐