Mybatis中Integer类型的判断<if test=“status!= null and status!= ‘‘“>问题


Mybatis在进行<if test="status!= null and status!= ''">判空操作时,如果status为0的时候,该判断条件的值为false,也就是说Mybatis此时把0作为null来进行判断的

此时就会出现问题,在查询状态是0的数据时,查询的是全部数据

 

解决办法:

将判断条件修改为:<if test="status!= null">

结论:

  1. <if test="status != null">中status为integer类型的,status=0的判断结果为true。
  2. <if test="status != null and status != ''">中status为integer类型的,status=0的判断结果为false,mybatis把status看作string来进行判断。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM