问题-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. C#基础知识记录一

    C#基础知识记录一 static void Main(string[] args) { #region 合并运算符的使用(合并运算符??) 更多运算符请参考:https://msdn.microsof ...

  2. LeetCode Find All Anagrams in a String

    原题链接在这里:https://leetcode.com/problems/find-all-anagrams-in-a-string/ 题目: Given a string s and a non- ...

  3. Linux下查看某进程相关进程

    1- ps -T <pid> ###pid表示进程号 或者ps -T -p <pid> 2-   top -H -p <pid>  ###pid表示进程号 3-  ...

  4. js实现Dictionary

    js是有Dictionary对象的,只是只有在IE浏览器下可以使用. var dic = new ActiveXObject("Scripting.Dictionary"); 但是 ...

  5. sed 引入shell变量

    双单引号即可 1.eval sed ’s/$a/$b/’ filename2.sed "s/$a/$b/" filename3.sed ’s/’$a’/’$b’/’ filenam ...

  6. hp安装oracle报错解决

    hpux上安装oracle 11gR2刚开始报错:集群验证框架内部发生了错误 解决办法http://www.it165.net/database/html/201509/14181.html 将文件后 ...

  7. 关于使用FusionCharts生成图表时出现invalid xml data错误提示的解决方法

    FusionCharts的确功能是够强大的.收集的功能估计更强大.在初次使用时,对着手册,一步一步操作,就是生成图表工具不成功.一直报"Invalid xml data"错误.后面 ...

  8. 总结Android中遇见的OOM

    一 .Android应用中内存泄漏几种的原因: 1.单例模式导致的内存泄漏: 当调用getInstance时,如果传入的context是Activity的context.只要这个单例没有被释放,这个A ...

  9. hdu5714 拍照[2016百度之星复赛C题]

    由于船移动的速度都一样,那么对于往一个方向的船相对距离其实是不变的,我们可以把往一个方向移动的船都视作静止,并求出在哪些观测位置可以看到,很明显对于船[x,y,z],当x+z>=y-z的时候,可 ...

  10. CentOs中yum安装LAMP+PHPMYADMIN

    对于租用以及VPS,提供在Linux安装LAMP(Linux+Apache+mysql+PHP),对于这个组件,不做过多的解释,网上很多这方面的资料.下面只介绍一种安装方法,作为以后使用的一个简单文档 ...