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>判断原理。下图来自文心一言

相关推荐
qqacj12 小时前
SpringBoot3.3.0集成Knife4j4.5.0实战
java
煎饼皮皮侠12 小时前
利用 AQS 构建一个自己的公平共享锁
java·aqs·公平共享锁
梁山话事人12 小时前
Spring IOC
java·数据库·spring
计算机学姐12 小时前
基于SpringBoot的奶茶店点餐系统【协同过滤推荐算法+数据可视化统计】
java·vue.js·spring boot·mysql·信息可视化·tomcat·推荐算法
程序员cxuan12 小时前
来了来了,Claude Code 全架构解析 !!!
人工智能·后端·claude
@土豆12 小时前
Java JVM参数环境变量详解及SkyWalking Agent集成技术文档
java·jvm·skywalking
Yupureki12 小时前
《Linux系统编程》19.线程同步与互斥
java·linux·服务器·c语言·开发语言·数据结构·c++
又来敲代码了12 小时前
Zrlog博客的系统部署
java·linux·运维·mysql·apache·tornado
砍光二叉树12 小时前
【设计模式】行为型-责任链模式
java·设计模式·责任链模式
艾莉丝努力练剑12 小时前
【Linux信号】Linux进程信号(下):可重入函数、Volatile关键字、SIGCHLD信号
linux·运维·服务器·c++·人工智能·后端·学习