mybatis `if test` 标签判断字符串

错误:

这里mentorType为String类型,运行后发现不生效。后尝试将'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>判断原理。下图来自文心一言

相关推荐
Rain的Java大神之路1 分钟前
LeetCode 46 全排列:从「及格答案」到让面试官眼前一亮的三种写法
后端·leetcode·面试
打工仔折腾 AI9 分钟前
Linux网络:UDP一次sendto对应一次recvfrom的底层机制解析
linux·网络·人工智能·后端·python·性能优化·udp
xieliyu.29 分钟前
Nacos 环境隔离与配置中心:改配置不用重启,真香(四)
后端·spring cloud·微服务·云原生·nacos·配置中心·动态刷新
金銀銅鐵32 分钟前
带您看懂字节码指令(Web 版):第一帧在浏览器里跑一遍
java·jvm·后端
阿策小和尚34 分钟前
4.3GB 依赖树压到 284MB、五进程 500ms 退场:我把 4 万星的 Novu 塞进了 Dopame OS
人工智能·后端·架构
码途行者42 分钟前
每天10分钟学Go:第31课 原子操作与互斥锁
开发语言·后端·golang
程序员阿明1 小时前
spring boot 4 + netty搭建JT808车载终端服务
spring boot·后端
飞花漫卷,情随岁迁1 小时前
命令进阶与 Playbook 快速入门
java·linux·运维·服务器·网络·数据库·智能路由器
hookserver1 小时前
企业微信 iPad 协议全功能接入效果实测
java·http·微信·企业微信·ipad