问题-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. warnin php startup in unknown on line 0:

    PHP Warning:  PHP Startup:  in Unknown on line 0 这种情况是因为扩展路径有问题导致的路径或错,或没有该扩展但ini中开启了此扩展

  2. 关于如何查看MySQL版本:

    方法一: 进入mysql cmd, status; 将显示当前mysql的version的各种信息. 方法二: 还是在mysql的cmd下,输入: select version(); 查看MySQL端 ...

  3. spring定时任务

    需求:在tomcat启动时开启一个定时任务,即项目启动完成后,自动执行某一特定任务. 想法:容器启动时执行方法,最容易想到的就是servlet中可以配置load-on-startup,设置一个正整数也 ...

  4. android 中获取当前焦点所在屏幕中的位置 view.getLocationOnScreen(location)

    final int[] location = new int[2]; view.getLocationOnScreen(location); final int[] location = new in ...

  5. hdfs shell 命令以及原理

    shell 操作 dfs 上传[hadoop@namenode ~]$ /data/hadoop/bin/hadoop fs -put /opt/MegaRAID/MegaCli/MegaCli64 ...

  6. jenkins配置邮件

    1.安装 Email Extension Plugin 插件 2.进入系统管理--系统设置 3.按照如下图设置 首先找到 Extended E-mail Notification  

  7. eclipse配置项目

    project facets -> dynamic web module 2.5 java -> 1.6 deployment assembly -> webapp Web Proj ...

  8. Zookeeper:通过yarn实现大型分布式管理系统

    http://www.cnblogs.com/leesf456/p/6063694.html

  9. Design and Analysis of Algorithms_Fundamentals of the Analysis of Algorithm Efficiency

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  10. linux scp 远程复制文件

    1.从本机复制文件到远程scp 文件名 远程计算机用户名@远程计算机的ip:远程计算机存放该文件的路径2.从远程复制文件到本机:scp 远程计算机用户名@远程计算机ip:文件名 存放该文件的本机路径3 ...