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

相关推荐
呱牛do it2 小时前
企业级门户网站设计与实现:基于SpringBoot + Vue3的全栈解决方案(Day 3)
java·vue
神の愛3 小时前
左连接查询数据 left join
java·服务器·前端
南境十里·墨染春水3 小时前
linux学习进展 线程同步——互斥锁
java·linux·学习
雨奔3 小时前
Kubernetes 联邦 Deployment 指南:跨集群统一管理 Pod
java·容器·kubernetes
杨凯凡3 小时前
【021】反射与注解:Spring 里背后的影子
java·后端·spring
IT摆渡者3 小时前
MySQL性能巡检脚本分析报告
数据库·mysql
lulu12165440783 小时前
Claude Code项目大了响应慢怎么办?Subagents、Agent Teams、Git Worktree、工作流编排四种方案深度解析
java·人工智能·python·ai编程
riNt PTIP3 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring
Ares-Wang4 小时前
Flask》》 Flask-Bcrypt 哈希加密
后端·python·flask
小码哥_常4 小时前
Spring Boot项目大变身:为何要拆成这六大模块?
后端