mybatis `if test` 标签判断字符串

错误:

这里mentorTypeString类型,运行后发现不生效。后尝试将'1'改为双引号,问题解决。

java 复制代码
<if test="mentorType != null and mentorType!='' and mentorType=='1' ">
       AND u.student_mentor_id = #{searchValue}
</if>

正确写法:

java 复制代码
<if test='mentorType != null and mentorType!="" and mentorType=="1" '>
       AND u.student_mentor_id = #{searchValue}
</if>

搜了一下,不少人遇到这个问题,并提供了另一种解决方法:用单引号时这样写

java 复制代码
'1'.toString()

鉴于能力有限,不能进一步深入研究mybatis <if test>判断原理。下图来自文心一言

相关推荐
百万蹄蹄向前冲2 小时前
Trae Genimi3跟着官网学实时通信 Socket.io框架
前端·后端·websocket
狂炫冰美式3 小时前
TRAE SOLO 驱动:重构AI模拟面试产品的复盘
前端·后端·面试
x***38166 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
“αβ”6 小时前
MySQL表的操作
linux·网络·数据库·c++·网络协议·mysql·https
S***84886 小时前
SpringSecurity踢出指定用户
java
p***s916 小时前
Spring数据库原理 之 DataSource
java·数据库·spring
adobehu6 小时前
麒麟系统安装jdk17
java·jdk
spencer_tseng6 小时前
java.util.IllegalFormatPrecisionException
java·printf
虹科网络安全6 小时前
艾体宝干货 | Redis Java 开发系列#1 从零开始的环境搭建与实践指南
java·数据库·redis
铅笔侠_小龙虾6 小时前
Arthas 命令
java·jvm