MyBatis条件查询对字段判断是否为空一般为:

<if test="testValue!=null and testValue != ''">
and test_value = #{testValue}
</if>

如果传入参数为Integer类型且值为0时,会把0转为空串

源码真实情况是:

MyBatis解析的所有sqlNode节点,针对if节点会交给IfSqlNode来处理,进过层层处理,最终都会调用OgnlOps.class类的doubleValue(Object value)方法

public static double doubleValue(Object value) throws NumberFormatException {
if (value == null) {
return 0.0D;
} else {
Class c = value.getClass();
if (c.getSuperclass() == Number.class) {
return ((Number)value).doubleValue();
} else if (c == Boolean.class) {
return ((Boolean)value).booleanValue() ? 1.0D : 0.0D;
} else if (c == Character.class) {
return (double)((Character)value).charValue();
} else {
String s = stringValue(value, true);
return s.length() == 0 ? 0.0D : Double.parseDouble(s);
}
}
}

0和""都调用该方法返回的double值都为0.0,在进行比较。

处理方法:

<if test="testValue!=null and testValue!='' or 0 == testValue">
and test_value = #{testValue}
</if> 或者 <if test="testValue!=null">
and test_value = #{testValue}
</if>

MyBatis参数条件查询传入的值为0时的判断的更多相关文章

  1. MyBatis参数为Integer型并赋值为0时判断失误的问题解决

    mybatis.xml中有if判断条件判断参数不为空时,赋值为0的Integer参数被MyBatis判断为空,因此不执行<if test="param != null and para ...

  2. Mybatis多条件查询

    在Mybatis多条件查询中: 1.参数如果是多条件,则需要将将添加到Map集合中进行传入. 2.就是将其参数用有序数字进行代替. Mybatis单个String类型参数传递 mysql文如下,传入参 ...

  3. mybatis 按照条件查询

    mybatis 按照条件查询 @Autowired private StudentMapper studentMapper; @Override public Map getStudentList(i ...

  4. SSM整合 mybatis多条件查询与分页

    多条件查询与分页: 通过页面的houseName.floorage获取值传到前端视图(HouseSearchVO)实体类中的houseName,floorage建立houseSearchVO对象. 通 ...

  5. jqGrid jqGrid分页参数+条件查询

    HTML <div class="row"> <div class="col-sm-20"> <form id="for ...

  6. Mybatis中 Integer 值为0时,默认为空字符串的解决办法。

    需求是查询级别为0的用户 User对象里的level字段的值为0,查询时居然没有查到为level为0的用户. <select id="selectSelective" par ...

  7. SqlParameter设定的value值为0时、调用的存储过程获取到的值却为null解决方法

    原C#代码如下: if (query != null) { switch (query.MethodFlag) { //进出口退补税额统计表 case (int)EnumClassifyCorrect ...

  8. mybatis参数传参、取值处理等

    单个参数:mybatis不会做特殊处理 取值方式:#{参数名} 这里参数名不必与方法的形参名称一致,可以用任意参数名来接受实参 例子:方法:update(Integer id) sql映射文件取值#{ ...

  9. Mybatis实现条件查询(三)

    1. 准备 请先完成Mybatis基本配置(一)的基本内容 2. 疑问 我们再Mybatis基本配置(一)中实现了按照商品ID进行查询商品信息,可是在实际应用中却很少出现根据ID来查询商品的情况.因为 ...

随机推荐

  1. Tasking

    Put your plan on the tick list, and set the completion time limit, daily repetition, etc. according ...

  2. K-string HDU - 4641 (后缀自动机)

    K-string \[ Time Limit: 2000 ms\quad Memory Limit: 131072 kB \] 题意 给出长度为 \(n\) 的字符串,接下来跟着 \(m\) 次操作, ...

  3. (尚030)Vue_案例_存储数据(localStorage本地存储技术)

    当刷新页面时,会变为原来的状态 1.问题:当我刷新是不希望改变原来状态 需要缓存我当前的数据 2.究竟是缓存在内存里还是在文件里??? 缓存在文件里,因为浏览器关闭了,内存就没了;而我们需要重新打开浏 ...

  4. GoCN每日新闻(2019-11-09)

    GoCN每日新闻(2019-11-09) 1. Go语言发行10周年庆祝 https://blog.golang.org/10years2. 容器中某Go服务GC停顿经常超过100ms排查 https ...

  5. R 语言中的数据结构

    基本数据类型 6种 numaric  如 12, 12.4 integer  如 2L,0L complex  包含实数和虚数 如 3+2i character  要用双引号或者单引号包括起来 如 & ...

  6. docker-nginx 与 tomcat--dockerfile

    nginx: FROM nginx:latest COPY nginx/sources.list /etc/apt/sources.list #RUN apt-get update && ...

  7. js - try..catch详解

    try... catch 1.try...catch和if语句 为什么不用if替换调try...catch? 大部分人都有这样想法 if=>只能判断用户操作 try...catch=>来自 ...

  8. freeNas 数据record

  9. Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.

    写在前面 部署项目到weblogic上启动首页访问空白, 浏览器控制台报如题错误. web.xml中把响应头添加防止攻击的报文过滤器禁用就行了(仅仅是为了启动), 以下为转载内容, 可以根据需要自行测 ...

  10. label vc

    #pragma once #include <QWidget> #include <QPaintEvent> #include <QPainter> #includ ...