解决——》MyBatis把0当做空字符串
版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者。
https://blog.csdn.net/weixin_43453386/article/details/83823071
解决——》MyBatis把0当做空字符串
- 1、操作
- 2、现象(错误信息)
- 3、原因
- 4、解决
1、操作
MyBatis使用xml配置执行sql语句:插入数据和更新数据
2、现象(错误信息)
<sql id="sql_update">
update community_gate_addr set id = #{item.id}
<if test="null != item.communityId and '' != item.communityId ">, community_id = #{item.communityId}</if>
where id = #{item.id}
</sql>
3、原因
Integer和BigDecimal类型作数值传递,mybatis会把参数0当成是空字符串去判断
4、解决
将0转化为String类型
<sql id="sql_update">
update community_gate_addr set id = #{item.id}
<if test="null != item.communityId and '' != item.communityId or item.communityId=='0'.toString()">, community_id = #{item.communityId}</if>
where id = #{item.id}
</sql>
还没有评论,来说两句吧...