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

相关推荐
BingoGo4 小时前
PHP clone 之后,为什么改副本会影响原对象?
后端·php
JaguarJack5 小时前
PHP clone 之后,为什么改副本会影响原对象?
后端·php·服务端
小灰灰搞电子5 小时前
Rust+Slint 实现动态消息提示框源码分享
开发语言·后端·rust
魏 无羡5 小时前
webclient
java·webclient
小奏技术5 小时前
10 MB 的 Postman 替代品,启动不到 1 秒
后端
东风破_5 小时前
Text2SQL :用自然语言操作 SQLite 数据库
人工智能·后端
神仙别闹6 小时前
基于 C++ 实现两个有序链表序列的交集
java·c++·链表
swordbob7 小时前
ReentrantLock 与 AQS 完整学习手册
java·开发语言
₍˄·͈༝·͈˄*₎◞ ̑̑码7 小时前
MyBatis操作数据库
数据库·mybatis
m0_587383008 小时前
全民健身解决方案软件开发实战:从架构设计到落地指南
java·spring boot·spring·架构·需求分析