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

相关推荐
彦楠6 小时前
指定Tomcat运行的JDK地址
java·开发语言·tomcat
隐退山林6 小时前
JavaEE进阶:MyBatis操作数据库(进阶)
数据库·java-ee·mybatis
Byron__7 小时前
JVM垃圾回收与调优核心面试笔记(引用计数/GC算法/CMS/G1/参数调优)
java·jvm·笔记·面试
XiYang-DING7 小时前
【Spring】 SpringBoot 配置文件
java·spring boot·spring
我是一颗柠檬7 小时前
【MySQL全面教学】MySQL锁机制与并发控制Day10(2026年)
数据库·sql·mysql·database
那小子、真烦7 小时前
Hermes Agent Chat 方法分析
java·开发语言
01_ice7 小时前
Java抽象类和接口
java·开发语言
小马爱打代码7 小时前
Spring源码 第七篇:Spring Boot 自动配置原理深度拆解
java·spring boot·spring
fen_fen7 小时前
Oracle12,新增自增主键表和批量插入数据
数据库·sql·mysql
念恒123067 小时前
MySQL索引
数据库·mysql