mybatis判断字符串等于
前言:我们通常使用mybatis过程中,对于判断一个变量是否为空的时候,使用 <if test="xxx != null and xxx !=''">进行。
有个小坑如下:
<if test=" name!=null && name =='admin' "><if/>
这样子写会出现 后面的 name =='admin' 失效问题。
解决方案1:
<if test='name!=null && name =="admin"'><if/> # 把这个转换成 单引号。
解决方案2:
<if test=" name!=null && name =='admin'.toString() "><if/>
————————————————
<if test="params.cyzt!= null and params.cyzt != ''">
<choose>
<when test='params.cyzt =="在院"'>
and cyrq is null or cyrq='0000-00-00 00:00:00'
<if test="params.beginRyrq != null and params.beginRyrq != '' and params.endRyrq != null and params.endRyrq != ''"> and ryrq between #{params.beginRyrq} and #{params.endRyrq}</if>
</when>
<when test='params.cyzt =="出院"'>
and cyrq is not null and cyrq!='0000-00-00 00:00:00'
<if test="params.beginRyrq != null and params.beginRyrq != '' and params.endRyrq != null and params.endRyrq != ''"> and cyrq between #{params.beginRyrq} and #{params.endRyrq}</if>
</when>
<otherwise>
</otherwise>
</choose>
</if>
分类:
mybatis
posted on 2022-08-17 12:04 zyp_java_net 阅读(1836) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?