解决——》MyBatis把0当做空字符串

淩亂°似流年 2023-10-21 06:58 194阅读 0赞

版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者。
https://blog.csdn.net/weixin_43453386/article/details/83823071

解决——》MyBatis把0当做空字符串

    • 1、操作
    • 2、现象(错误信息)
    • 3、原因
    • 4、解决

1、操作

MyBatis使用xml配置执行sql语句:插入数据和更新数据

2、现象(错误信息)

  1. <sql id="sql_update">
  2. update community_gate_addr set id = #{item.id}
  3. <if test="null != item.communityId and '' != item.communityId ">, community_id = #{item.communityId}</if>
  4. where id = #{item.id}
  5. </sql>

3、原因

Integer和BigDecimal类型作数值传递,mybatis会把参数0当成是空字符串去判断

4、解决

将0转化为String类型

  1. <sql id="sql_update">
  2. update community_gate_addr set id = #{item.id}
  3. <if test="null != item.communityId and '' != item.communityId or item.communityId=='0'.toString()">, community_id = #{item.communityId}</if>
  4. where id = #{item.id}
  5. </sql>

发表评论

表情:
评论列表 (有 0 条评论,194人围观)

还没有评论,来说两句吧...

相关阅读