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

相关推荐
WF_YL几秒前
IntelliJ IDEA 关闭保存时在文件末尾换行 -(取消保存自动末尾换行)
java·ide·intellij-idea
撩得Android一次心动3 分钟前
Android Lifecycle 全面解析:掌握生命周期管理的艺术(1)
android·java·kotlin·lifecycle
lang201509284 分钟前
Java高性能缓存库Caffeine全解析
java·缓存·linq
专注于大数据技术栈5 分钟前
java学习--什么是线程安全和不安全
java·学习·安全
进击的小菜鸡dd5 分钟前
互联网大厂Java面试:从Spring Boot到微服务架构的场景化技术问答
java·spring boot·redis·ci/cd·微服务·消息队列·mybatis
IT19957 分钟前
IDEA+JDK11编译SpringCore5源码及替换项目中的Springcore
java·ide·intellij-idea
techzhi7 分钟前
IntelliJ IDEA 启动卡顿问题排查与解决
java·ide·intellij-idea
WayneJoon.H11 分钟前
2023CISCN deserbug复现
java·安全·web安全·cc链·反序列化
week_泽11 分钟前
第8课:LangGraph Memory管理机制与实现方案 - 学习笔记_8
java·笔记·学习·ai agent
李日灐12 分钟前
C++STL:仿函数、模板(进阶) 详解!!:“伪装术”和模板特化、偏特化的深度玩法指南
开发语言·c++·后端·stl