问题-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( ...
随机推荐
- 【leedcode】 Longest Palindromic Substring
Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...
- 用Apache生产csr申请证书
一. 安装Apache: 1.安装完成后将apache安装目录下 conf 文件夹中的"openssl.cnf"文件复制到bin文件夹中: 2.配置Apache支持ssl: 打开A ...
- iOS程序中的内存分配 栈区堆区全局区
在计算机系统中,运行的应用程序的数据都是保存在内存中的,不同类型的数据,保存的内存区域不同.一.内存分区 栈区(stack) 由编译器自动分配并释放,存放函数的参数值,局部变量等.栈是系统数据结构,对 ...
- Issue 2:Introduction 方法论
1 清晰的思路 论文投稿完毕,彻底完事儿后,原本很反感的论文书写过程也有了些许心得:论文就是科研工作的文字总结,知识再提炼的过程. 想要写好Introduction,脑子里的一条主线必须清楚. 1.1 ...
- simple_tag,filte,分页以及cookie和装饰器
自定义simple_tag 内置的方法 首先Django中包含了很多内置的方法: 这里通过lower实现 在views视图函数中写如下代码: def tp3(request): name= " ...
- PCB的封装尺寸
PCB封装主要分为贴片式与插件式 1)贴片元件封装说明发光二极管:颜色有红.黄.绿.蓝之分,亮度分普亮.高亮.超亮三个等级,常用的封装形式有三类:0805.1206.121 (常用封装为RB.1/. ...
- weblogic10异常:org.hibernate.hql.ast.HqlToken
转自:http://www.programgo.com/article/68682994452/ 在做查询的时候,报出 org.hibernate.QueryException: ClassNotF ...
- HTML5--div、span超出部分省略号显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JsonOperate 帮助类
引用 Newtonsoft.Json using Newtonsoft.Json; using System; using System.Collections.Generic; using Syst ...
- Linux主机规划
当你想装linux操作系统的时候,一定要知道你的用途,不同的用途就要规划不同的装机方式. 首先要知道一些概念: 挂载:利用一个目录当成进入点,将磁盘分区的数据放置在该目录下. 磁盘第一个扇区记录的信息 ...