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

相关推荐
lizhongxuan1 小时前
Claude Code 防上下文爆炸:源码级深度解析
前端·后端
Via_Neo1 小时前
JAVA中以2为底的对数表示方式
java·开发语言
·云扬·2 小时前
【MySQL】实战:用pt-table-sync修复主从数据一致性问题
数据库·mysql·ffmpeg
Warson_L2 小时前
Python 流程控制与逻辑
后端·python
糖炒栗子03262 小时前
架构笔记:应用配置无状态化 (Statelessness)
后端
野生技术架构师2 小时前
一线大厂Java面试八股文全栈通关手册(含源码级详解)
java·开发语言·面试
Warson_L3 小时前
Python 四大组合数据类型 (Collection Types)
后端·python
廋到被风吹走3 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
swIn KWAL3 小时前
【MySQL】环境变量配置
数据库·mysql·adb
shark22222223 小时前
【JOIN】关键字在MySql中的详细使用
数据库·mysql