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

相关推荐
NGC_66112 分钟前
ConcurrentHashMap1.8 多线程扩容机制
java·开发语言
代码派3 分钟前
SQL 审核解决了部分问题,另一部分是慢 SQL 治理
数据库·sql·mysql·数据库管理工具·ninedata·sql审核·sql治理
ssshooter7 分钟前
Tauri 2 Linux 上 asset://localhost 访问返回 403 避坑指南
前端·后端·架构
东离与糖宝9 分钟前
不用Python!Java+Spring AI 3.x本地RAG系统搭建实战
java·人工智能
堕27412 分钟前
JavaEE初阶——《多线程--. 多线程带来的的⻛险-线程安全 (重点)》
java·算法·java-ee
book123_0_9914 分钟前
spring 跨域CORS Filter
java·后端·spring
空空潍14 分钟前
Spring AI 实战教程(一)入门示例
java·后端·spring·ai
星辰_mya15 分钟前
自定义注解 + AOP:打造企业级通用组件(日志、限流、幂等)
java·开发语言·spring·面试·架构师
大阿明19 分钟前
Go基础之环境搭建
开发语言·后端·golang
qq_3660862220 分钟前
MyBatis 动态 SQL 高频性能优化方案
sql·性能优化·mybatis