问题-MyBatis不识别Integer值为0的数据

问题:使用MyBatis的过程中,发现一个值为0的数据,Mybatis所识别,最后定位才发现,是自己的写法有问题,

  1. <if test="form.passLine != null and  form.passLine != '' ">
  2. and is_live =  #{form.passLine,jdbcType=INTEGER}
  3. </if>

更正成:

  1. <span style="color:#FF0000;"> <if test="form.passLine != null and  form.passLine != -1 ">
  2. and is_live =  #{form.passLine,jdbcType=INTEGER}
  3. </if></span>

完美解决。

Mybatis Integer类型,值为0被认为是空字符串的解决办法

mybatis写update时,正常是set了值才会进行update操作,我们一般是这样写。

<if test="sampleBatchNo != null and sampleBatchNo != ''" >
SAMPLE_BATCH_NO = #{sampleBatchNo,jdbcType=VARCHAR},
</if>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

如果不空null并且不是空字符串才去修改这个值,但这样写只能针对字符串(String)类型,如果是Integer类型的话就会有问题了。

int i = 0;
i!=''。
mybatis中会返回true。也就是说,mybatis将i==0的值也认定为空字符串。
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

正常来说,0不为空也不是空字符串。所以,针对这个问题,我的解决办法是:如果类型为Integer类型,我就去掉 != ”的判断,只判断!=null即可。

以下是代码:

  1. <select id="countPageByParam" resultType="java.lang.Long">
  2. select count(id)
  3. from lms_teacher_info
  4. where 1=1
  5. and city_id = #{form.cityId,jdbcType=VARCHAR}
  6. AND update_time =  #{updateTime,jdbcType=VARCHAR}
  7. <if test="form.period != null and form.period != '' ">
  8. and period_fourweek_start = #{form.period,jdbcType=VARCHAR}
  9. </if>
  10. <if test="form.schoolId != null and form.schoolId != '' ">
  11. and school_id = #{form.schoolId,jdbcType=VARCHAR}
  12. </if>
  13. <span style="color:#FF0000;"> <if test="form.passLine != null and  form.passLine != -1 ">
  14. and is_live =  #{form.passLine,jdbcType=INTEGER}
  15. </if></span>
  16. <if test="form.streetId != null and form.streetId != '' ">
  17. and street_id = #{form.streetId,jdbcType=VARCHAR}
  18. </if>
  19. <if test="form.districtId != null and form.districtId != '' ">
  20. and district_id LIKE CONCAT( #{form.districtId,jdbcType=VARCHAR} , '%')
  21. </if>
  22. <if test="form.keyword != null and form.keyword !='' ">
  23. and (
  24. teacher_name LIKE CONCAT( #{form.keyword,jdbcType=VARCHAR} , '%')
  25. or teacher_id = #{form.keyword,jdbcType=VARCHAR}
  26. )
  27. </if>
  28. </select>

问题-MyBatis不识别Integer值为0的数据的更多相关文章

  1. 摘录-Mybatis - Integer值为0的数据 return false

    Mybatis在进行<if test="status != null and status != ''">判空操作时,如果status为0的时候,该判断条件的值为fal ...

  2. Mybatis中 Integer 值为0时,默认为空字符串的解决办法。

    需求是查询级别为0的用户 User对象里的level字段的值为0,查询时居然没有查到为level为0的用户. <select id="selectSelective" par ...

  3. MyBatis参数条件查询传入的值为0时的判断

    MyBatis条件查询对字段判断是否为空一般为: <if test="testValue!=null and testValue != ''"> and test_va ...

  4. 数据库TINYINT类型 参数0 mybatis取不到值

    tinyint存储0的奇怪问题  数据库TINYINT类型   参数0  mybatis取不到值 postman 传参 audited   =0          audited   =1  两种情况 ...

  5. mybatis中使用Integer类型的参数<if>判断问题

    mybatis对传入参数进行判断时,会使用if标签, 一般是判断不为null和'', 如下: <if test="name != null and 那么 != ''"> ...

  6. 火狐、谷歌、IE关于document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题

    一.先遇到document.body.scrollTop值为0的问题 做页面的时候可能会用到位置固定的层,读取document.body.scrollTop来设置层的位置,像这样, window.on ...

  7. document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题

    转自http://wo13145219.iteye.com/blog/2001598 一.先遇到document.body.scrollTop值为0的问题 做页面的时候可能会用到位置固定的层,读取do ...

  8. Android 在xml中配置 float 和 integer 值

    一.float的配置方法 andriod 默认不支持float型的设置,在values 下的新建floats.xml 文件,在内部添加如下代码: <resources> <item ...

  9. 判断Integer值相等最好不用==(未整理)

    今天在开发中判断两个Integer值相等, Integer a = 3; Duixiang duixiang = new Duixiang(); duixiang = DAO.getDuixiang( ...

随机推荐

  1. 用Pyinstaller打包发布exe应用

    有时候编写的Python程序依赖很多,如果要在不同服务器上安装python环境等东西有点得不偿失了.这时候可以使用pyinstaller和py2exe,能够将python程序打包成可执行的exe文件, ...

  2. oracle正则表达式的用法

    <SPAN style="FONT-SIZE: 18px">Oracle 正则表达式函数-REGEXP_SUBSTR 使用例子 .5个参数 第一个是输入的字符串 第二个 ...

  3. 弱网测试Android

    弱网测试一般是指模拟在网络环境比较差的情况下,检测APP是否有异常,如崩溃,数据收发出现丢包的情况 一.首先需要控制网络,有两种方式其一使用网络损伤仪进行,其二采用软件方式.硬件采购费用太贵,因此使用 ...

  4. linux 查找文件的命令

    http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html

  5. CentOS 系统目录解析

    CentOS 系统目录解析 http://mp.weixin.qq.com/s?__biz=MzAxOTAzMzEzNg==&mid=202463614&idx=2&sn=51 ...

  6. vim - copy/paste a word

    1. http://stackoverflow.com/questions/7797068/copying-a-word-and-pasting-over-a-word viwp - visually ...

  7. python入门到精通[二]:基础学习(1)

    摘要:Python基础学习: 注释.字符串操作.用户交互.流程控制.导入模块.文件操作.目录操作. 上一节讲了分别在windows下和linux下的环境配置,这节以linux为例学习基本语法.代码部分 ...

  8. 如何使用抓包工具fiddler对app进行接口分析

    如果你还不知道什么是抓包,点我 如果你还不知道什么是http,点它 如果你想知道什么是fiddler 什么是接口测试 正文来了.安装fiddler后,打开界面,点击tools,找到如图的options ...

  9. 返回值是TEXT的阿贾克斯方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. debian bcm43* 无线网卡驱动

    deb http://httpredir.debian.org/debian/ jessie main contrib non-free # apt-get update# apt-get insta ...