美文网首页
MyBatis integer 0 判断为空

MyBatis integer 0 判断为空

作者: 之乏 | 来源:发表于2018-08-28 14:33 被阅读0次

问题重现:

operateResult=0, 不进入条件, 导致sql更新时operateResult字段明明传值却未更新

operateResult=1, 却进入条件

mybatis写批量update时, 有这么个判断

<iftest="item.operateResult !=null and item.operateResult !=''">

         OPERATE_RESULT= #{item.operateResult},

</if>

正常情况下理解为, operateResult不为null不为空字符串才会进入.

但这种情况是针对字符串(String)类型,如果是Integer类型的话就会有问题


1. mybatis 默认认为Integer 类型字段等于0是 == ""

2.站在java角度上, Integer类型本来就不允许等于"",只允许为null

解决方法:

将and item. operateResult!=''"去掉, 只 判 断 item. operateResult!=null

相关文章

网友评论

      本文标题:MyBatis integer 0 判断为空

      本文链接:https://www.haomeiwen.com/subject/grofwftx.html