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

相关推荐
2601_953824613 分钟前
基于SSM的水果超市管理系统
java·tomcat·maven
guo_wen_qiang5 分钟前
springboot如何自定义一个启动器starter
java·spring boot·intellij-idea
许彰午9 分钟前
55-字典缓存与通知SPI
java·低代码·架构
captain37614 分钟前
HTTP(2)
java·网络·http·java-ee
徐子童16 分钟前
介绍MVCC机制
java·mysql·面试题·秋招·并发·mvcc
Wang's Blog17 分钟前
Java 项目实战: 外卖平台-启用禁用员工账号与Long精度丢失修复
java·服务器
乌暮22 分钟前
Java 抽象类与接口详解:半成品图纸 vs 能力合同
java·开发语言·后端·学习
thefool11226624 分钟前
库和表基本操作、表的增删改查
mysql
一条泥憨鱼29 分钟前
苍穹外卖【day12| 工作台,通过Apache POI导入/导出运营数据】
java·后端·苍穹外卖
心平气和量大福大34 分钟前
android-权限
android·java