Mybatis if判断Integer类型的值

问题描述:当传入的   status值为0 时,不进入 if 判断

复制代码
    <select id="selectAll" parameterType="com.imes.domain.entities.User" resultMap="BaseResultMap">
        select * from user
        <where>          
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
    </select>  
复制代码

执行语句为:

1
select * from user   

原因:

如果是Integer类型的话,如果变量的值是0,即 status = 0, 、
mybatis在进行 status != '' 的时候会认为  status  的值是空字符串, 即 status == '' 为true。

结论:

1
如果是Integer类型只需要判断 != null 即可

 

posted @   唏嘘-  阅读(727)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示