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

相关推荐
知识汲取者9 分钟前
巨量引擎 Marketing API Java SDK 介绍
java·开发语言
182******208311 分钟前
2026年40岁自学java还能找到工作吗
java·开发语言
tool24 分钟前
hermes自动发布公众号
后端
yuzhiboyouye29 分钟前
java线程池
java·开发语言·firefox
网络工程小王1 小时前
【LCEL 链式调用详解】调用篇-2
java·服务器·前端·数据库·人工智能
swipe1 小时前
别把语音 Agent 当成“接两个 API”——用 NestJS 搭一套 ASR + LLM + 流式 TTS 的实时语音助手
前端·后端·llm
skilllite作者1 小时前
SkillLite 原生系统级沙箱功能代码导览
人工智能·chrome·后端·架构·rust
GISer_Jing1 小时前
AI Agent中游产业链全景拆解:智能体开发的核心生态与技术版图
前端·人工智能·后端
Zzzzmo_1 小时前
【JavaEE】文件操作和IO
java·java-ee·io·文件操作·file·流对象