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

相关推荐
程序员爱钓鱼1 分钟前
Go switch 详解
后端·面试·go
程序员爱钓鱼4 分钟前
Rust Struct结构体详解:定义自己的复杂数据类型
后端·面试·rust
风流 少年8 分钟前
Spring AI 2.0:MCP
java·后端·spring
北斗落凡尘33 分钟前
LangGraph 入门实战(7)
后端·langchain
天疆说36 分钟前
01 硬件选型与 llama.cpp 部署:4× RTX 5880 Ada 跑 DeepSeek-V4-Flash
java·redis·llama
uzong1 小时前
业务新老系统数据迁移-负责人经验总结和复盘
后端
水无痕simon1 小时前
3 短信应用场景以及平台架构
java·服务器
dogstarhuang1 小时前
大模型 API 停服怎么办:用 API 网关实现多模型统一接入与可切换架构
人工智能·后端·架构·大模型·api·数字化转型·ai应用
mister_guo1 小时前
JVM 内存管理原理及生产配置实战:从“参数能启动”到“内存可控”
java·jvm