【MyBatis】MyBatis中if标签正确使用方法(Integer类型)
前言
持久层:MyBatis
组合查询一组数据,字段有:String Integer 类型。
由于字段都可能为空,所以mapper文件中这样写的:
实践
但是此时并不能正确的查询到数据
问题原因:
status=‘’
MyBatis解析if标签时其表达式使用OGNL处理的。
Interpreting Objects as Booleans
Any object can be used where a boolean is required. OGNL interprets objects as booleans like this:
If the object is a Boolean, its value is extracted and returned;
If the object is a Number, its double-precision floating-point value is compared with zero; non-zero is treated as true, zero as false;
If the object is a Character, its boolean value is true if and only if its char value is non-zero;
Otherwise, its boolean value is true if and only if it is non-null.
如果对象是Number类型,当传值为0时会被解析成false,否则为true,浮点型0.00也是如此。所以这里直接解析成false。只有String类型才需要判断是否!=’’,其他类型完全没有这个必要。
解决方案:
__EOF__

本文链接:https://www.cnblogs.com/erlou96/p/16878196.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下