问题-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( ...
随机推荐
- wordpress取文章时间
wordpress的时间处理, 取文章的本地时间用get_the_time('c'),其中c可以用“D, d M Y H:i:s"等替代. 取文章的UTC时间用get_post_time(' ...
- Android 2D Graphics学习 Region和Canvas裁剪
1.首先介绍Region类 Region,中文意思即区域的意思,它表示的是canvas图层上的某一块封闭的区域. /**构造方法*/ public Region() //创建一个空的区域 publi ...
- jqGird 学习记录
jqGrid使用记录 Jqgrid教程(简单上手) jqGrid基本用法与示例 jqGrid中文教程(精品) $(document).ready(function () { $("#grid ...
- NOI 05:最高的分数描述
描述 孙老师讲授的<计算概论>这门课期中考试刚刚结束,他想知道考试中取得的最高分数.因为人数比较多,他觉得这件事情交给计算机来做比较方便.你能帮孙老师解决这个问题吗? 输入输入两行,第一行 ...
- Leetcode: Valid Word Abbreviation
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...
- linux scp 远程复制文件
1.从本机复制文件到远程scp 文件名 远程计算机用户名@远程计算机的ip:远程计算机存放该文件的路径2.从远程复制文件到本机:scp 远程计算机用户名@远程计算机ip:文件名 存放该文件的本机路径3 ...
- linux启动时文件系统错误问题
linux开机启动时,文件系统错误(磁盘有坏轨或文件系统出现错误) 原因: 1.系统运行时,突然断电或不正常关机,导致文件系统错误(文件系统错误并不是硬件错误,而是软件数据的问题) ...
- HTML5--页面自动居中
注意: margin:0 auto;/**0:上下 auto:左右**/ <html lang="en"> <head> <meta chars ...
- Notepad++自动刷新文本
现在的日志信息往往都是打印在硬盘上,而不是保存到线上,所以我们常常会使用notepad++来查看硬盘上的文本文件 这时往往会出现两个问题 (1)在notepad++长时间最小化后,再次打开会提示是否下 ...
- SVD java 算法实现
https://github.com/Richard-Cao/MatrixSvdDemo/blob/master/app/src/main/java/me/ele/caolicheng/matrixs ...