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

相关推荐
Java小卷5 小时前
KIE Drools 10.x 规则引擎快速入门
java·后端
fengsen52113145 小时前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
竟未曾年少轻狂5 小时前
Spring Boot 项目集成 Redis
java·spring boot·redis·缓存·消息队列·wpf·redis集群
_codemonster5 小时前
java web修改了文件和新建了文件需要注意的问题
java·开发语言·前端
Java天梯之路6 小时前
Spring Boot 钩子全集实战(九):`@PostConstruct` 详解
java·spring boot·后端
Lw老王要学习6 小时前
无互联网的正式 CentOS 7.6环境中安装 mysql-8.0.36-1
linux·服务器·mysql·centos
十间fish6 小时前
车载大端序和tcp大端序
后端
松涛和鸣6 小时前
75、 IMX6ULL LM75温度传感器I2C驱动开发
java·linux·数据库·驱动开发·python
独自破碎E6 小时前
BISHI41 【模板】整除分块
java·开发语言
树码小子6 小时前
Mybatis(7)其他查询操作(多表查询)
spring boot·mybatis