问题-MyBatis不识别Integer值为0的数据
问题:使用MyBatis的过程中,发现一个值为0的数据,Mybatis所识别,最后定位才发现,是自己的写法有问题,
- <if test="form.passLine != null and form.passLine != '' ">
- and is_live = #{form.passLine,jdbcType=INTEGER}
- </if>
更正成:
- <span style="color:#FF0000;"> <if test="form.passLine != null and form.passLine != -1 ">
- and is_live = #{form.passLine,jdbcType=INTEGER}
- </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即可。
以下是代码:
- <select id="countPageByParam" resultType="java.lang.Long">
- select count(id)
- from lms_teacher_info
- where 1=1
- and city_id = #{form.cityId,jdbcType=VARCHAR}
- AND update_time = #{updateTime,jdbcType=VARCHAR}
- <if test="form.period != null and form.period != '' ">
- and period_fourweek_start = #{form.period,jdbcType=VARCHAR}
- </if>
- <if test="form.schoolId != null and form.schoolId != '' ">
- and school_id = #{form.schoolId,jdbcType=VARCHAR}
- </if>
- <span style="color:#FF0000;"> <if test="form.passLine != null and form.passLine != -1 ">
- and is_live = #{form.passLine,jdbcType=INTEGER}
- </if></span>
- <if test="form.streetId != null and form.streetId != '' ">
- and street_id = #{form.streetId,jdbcType=VARCHAR}
- </if>
- <if test="form.districtId != null and form.districtId != '' ">
- and district_id LIKE CONCAT( #{form.districtId,jdbcType=VARCHAR} , '%')
- </if>
- <if test="form.keyword != null and form.keyword !='' ">
- and (
- teacher_name LIKE CONCAT( #{form.keyword,jdbcType=VARCHAR} , '%')
- or teacher_id = #{form.keyword,jdbcType=VARCHAR}
- )
- </if>
- </select>
问题-MyBatis不识别Integer值为0的数据的更多相关文章
- 摘录-Mybatis - Integer值为0的数据 return false
Mybatis在进行<if test="status != null and status != ''">判空操作时,如果status为0的时候,该判断条件的值为fal ...
- Mybatis中 Integer 值为0时,默认为空字符串的解决办法。
需求是查询级别为0的用户 User对象里的level字段的值为0,查询时居然没有查到为level为0的用户. <select id="selectSelective" par ...
- MyBatis参数条件查询传入的值为0时的判断
MyBatis条件查询对字段判断是否为空一般为: <if test="testValue!=null and testValue != ''"> and test_va ...
- 数据库TINYINT类型 参数0 mybatis取不到值
tinyint存储0的奇怪问题 数据库TINYINT类型 参数0 mybatis取不到值 postman 传参 audited =0 audited =1 两种情况 ...
- mybatis中使用Integer类型的参数<if>判断问题
mybatis对传入参数进行判断时,会使用if标签, 一般是判断不为null和'', 如下: <if test="name != null and 那么 != ''"> ...
- 火狐、谷歌、IE关于document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题
一.先遇到document.body.scrollTop值为0的问题 做页面的时候可能会用到位置固定的层,读取document.body.scrollTop来设置层的位置,像这样, window.on ...
- document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题
转自http://wo13145219.iteye.com/blog/2001598 一.先遇到document.body.scrollTop值为0的问题 做页面的时候可能会用到位置固定的层,读取do ...
- Android 在xml中配置 float 和 integer 值
一.float的配置方法 andriod 默认不支持float型的设置,在values 下的新建floats.xml 文件,在内部添加如下代码: <resources> <item ...
- 判断Integer值相等最好不用==(未整理)
今天在开发中判断两个Integer值相等, Integer a = 3; Duixiang duixiang = new Duixiang(); duixiang = DAO.getDuixiang( ...
随机推荐
- 可爱的Python_课后习题_CDay−5 Python 初体验和原始需求
计算今年是否是闰年.判断闰年条件,满足年份模400 为0,或者模4 为0 但模100不为0. def is_learp_year(year): """判断年份是否为润年& ...
- python csv用法
csv打开文件的时候,如下代码,出错: import csv name = "D:\\selenium\\data\\name.csv" inf= csv.reader(open( ...
- ElasticSearch 入门笔记1
1. 起步 1. 建demo工程,看文档,做典型demo 2. 资源列表: http://es.xiaoleilu.com/010_Intro/10_Installing_ES.html 3. 启动: ...
- Linux服务器ftp命令找不到
ftp commond not find 先用命令rpm -q vsftpd检查是否安装了ftp服务器 若显示vsftpd-2.2.2-11.el6_4.1.x86_64这样的信息,说明FTP服务器已 ...
- 安装hadoop集群服务器(hadoop1.2.1)
摘要:hadoop,一个分布式系统基础架构,可以充分利用集群的威力进行高速运算和存储.本文主要介绍hadoop的安装与集群服务器的配置. 准备文件: ▪ VMware11.0.0 ▪ Cen ...
- html中input标签的tabindex属性
当浏览者浏览网站时可以通过按TAB键在网页的链接中依次移动,这是一个相当方便实用的功能.但如果网页中链接太多,恐怕按TAB键就没什么作用了,这时不妨通过改变TAB键移动的顺序来突出重点,在某些重要页面 ...
- JSP中动态INCLUDE与静态INCLUDE的区别
动态INCLUDE 用法: <jsp:include page="included.jsp" flush="true" /> 说明: 它总是会检查所 ...
- jsonp
一次关于JSONP的小实验与总结 前言: 今天,无意间看到自己某个文件夹下有个JSONP的东西.慢慢回忆起,这个东西是之前想写的一个demo,也不知道是多久以前了,但是不知道怎么的,给忘那边了.那 ...
- github android
作者:ruijun 链接:https://www.zhihu.com/question/37160415/answer/79569042 来源:知乎 著作权归作者所有,转载请联系作者获得授权. ### ...
- Dev统计选中行、如需其他数据源可留言
Clipboard.Clear(); Dictionary<string, decimal> dtary = new Dictionary<string, decimal>() ...