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

相关推荐
Cx330❀7 小时前
【MySQL基础】一文吃透“表的约束”:从 Null/Default 到主外键的终极安全法则
linux·服务器·数据库·c++·mysql·安全
Java搬码工8 小时前
CompletableFuture 完整详解 + 全场景使用案例
java
许心月8 小时前
Java学习资料网站汇总
java
c238568 小时前
第二篇:《测试指挥官:可视化单题自测框架(含 assert 实操)》
java·数据库·c++·算法·安全性测试
大阳光男孩8 小时前
Spring Boot 整合 Debezium 实现 MySQL 增量数据监听(嵌入式版)
spring boot·后端·mysql
我科绝伦(Huanhuan Zhou)8 小时前
MySQL极端场景数据丢失防护:从Crash-Safe到异地备份
数据库·mysql
皮皮林5518 小时前
ThreadLocal 不香了?ScopedValue才是王道?
后端
帅次9 小时前
Kotlin 与 Java 互操作:混合工程里的平台类型与 API 边界
java·开发语言·kotlin·suspend·nullable
笨蛋不要掉眼泪9 小时前
MySQL架构揭秘:MVCC解决读一致性问题
数据库·mysql·架构
X-⃢_⃢-X9 小时前
一、第一阶段:认识 Spring Boot
java·spring boot·后端