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

相关推荐
日月云棠2 小时前
10 Integer —— 最常用的整数包装类深度解析
java·后端
大鸡腿同学2 小时前
大模型为何总 “胡说八道”?做完 RAG 知识库,我看懂了它的底层逻辑
后端
秋92 小时前
java项目中cpu飙升排查及解决方法
java·开发语言
野生技术架构师2 小时前
牛客网2026最新大厂Java高频面试题精选(附标准答案)
java·开发语言
PH = 72 小时前
JAVA的SPI机制
java·开发语言
一 乐2 小时前
高校实习信息发布网站|基于Spring Boot的高校实习信息发布网站的设计与实现(源码+数据库+文档)
java·数据库·spring boot·后端·论文·毕设·高校实习信息发布网站
安久12 小时前
springboot图片上传至服务器本地保存
后端
weelinking2 小时前
【产品】11_实现后端接口——数据在背后如何流动
java·人工智能·python·sql·oracle·json·ai编程
Dxy12393102162 小时前
三种方式避坑:案例 + 解决方法
python·mysql
摇滚侠3 小时前
东方通替换tomcat,实战经验
java