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

错误:

这里mentorType为String类型,运行后发现不生效。后尝试将'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>判断原理。下图来自文心一言

相关推荐
缓慢更新1 小时前
审批的加签与会签:多人意见怎么合
android·java·数据库·低代码·rxjava
前进的李工2 小时前
飞书企业知识库设计+后端高频八股
数据库·redis·后端·mysql·性能优化·飞书·rag
yuniko-n2 小时前
【JUC】volatile 非原子性深入解析
java
sun_weitao3 小时前
极简版 MCP 工具实现方案
java·linux·服务器
金銀銅鐵4 小时前
[Java] 展示增删元素时 LinkedList 的内部变化
java·后端·ai编程
为思念酝酿的痛4 小时前
MySQL数据类型
数据库·mysql
布吉岛的石头4 小时前
Java 程序员第 50 阶段3:数据工程:预训练语料清洗与去重
java·开发语言·人工智能·深度学习·transformer
大文说跨境5 小时前
防关联浏览器的指纹覆盖到什么程度:六类参数的实测与自检方法
java·指纹浏览器·tiktok运营
武子康5 小时前
Vercel Cache Reason:相同 MISS,怎样决定下一步查什么
人工智能·后端·agent
Carol06305 小时前
上肢及肩肘关节
java·服务器·数据库