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

相关推荐
ServBay2 小时前
打通 AI 编程本地运维边界,利用 MCP 协议简化环境与服务管理
后端·ai编程·mcp
程序员cxuan2 小时前
DeepSeek 杀入多模态,识图功能正式上线!
人工智能·后端·程序员
小猿姐4 小时前
MySQL Top 10 热点问题 AI 运维实战:从内核诊断到云原生运维
mysql·云原生·aiops
IT_陈寒5 小时前
SpringBoot这个自动配置坑我跳了三次
前端·人工智能·后端
用户395240998806 小时前
排坑日记:ASP.NET Core 中 "Required field is not provided" 验证错误全记录
后端
用户3521802454756 小时前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
用户8356290780516 小时前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
Oneslide7 小时前
sudo免密权限配置不生效
后端
站大爷IP7 小时前
为什么Python不用var或let声明变量?
后端