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>

posted on   zyp_java_net  阅读(1836)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示