问题-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. 原生js封装Ajax

    [转载请注明出处] 1 /** * @fileoverview ajax请求公用组件 * @author Limo * @date 2015/08/07 * Native package ajax m ...

  2. web api与webservice(转)

    webservice走HTTP协议和80端口而你说的api,用的协议和端口,是根据开发人员定义的 这么说吧,api类似于cs架构,需要同时开发客户端API和服务器端程序而WebService则类似于b ...

  3. struts2项目启动报错。关于jar的问题

    严重: Exception starting filter struts2 Unable to load configuration. - bean - jar:file:/D:/apache-tom ...

  4. 【vue.js权威指南】读书笔记(第一章)

    最近在读新书<vue.js权威指南>,一边读,一边把笔记整理下来,方便自己以后温故知新,也希望能把自己的读书心得分享给大家. [第1章:遇见vue.js] vue.js是什么? vue.j ...

  5. ps用画笔工具设计水墨圆环

    1.打开ps,新建一个1500*1500px的空白文档,分辨率为72,背景选择白色,如图: 2.选择画笔工具,按F5调出画笔预设面板,设置参数. 画笔笔尖形状:选择27号画笔,找不到可以复位一下画笔: ...

  6. Java提高篇——理解String 及 String.intern() 在实际中的应用

    1. 首先String不属于8种基本数据类型,String是一个对象.   因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. ...

  7. 002:IPC与system函数简介

    1:IPC名字mq_XXX,sem_XXX,shm_XXX. 消息队列 信号量 共享内存区 <mqueue.h> <semaphore.h> <sys.mman.h> ...

  8. 偶遇到 java.util.ConcurrentModificationException 的异常

    今天在调试程序 遇到了如此问题 贴上代码来看看稍后分析 List<String> list = null;boolean isUpdate = false;try { list = JSO ...

  9. csuoj 1119: Collecting Coins

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec  Memo ...

  10. [原创]java WEB学习笔记107:Spring学习---AOP切面的优先级,重用切点表达式

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...