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

相关推荐
卓怡学长1 小时前
m280本科生导师指导平台
java·数据库·spring·tomcat·maven·intellij-idea
武子康1 小时前
大数据-253 离线数仓 - Airflow 入门与任务调度实战:DAG、Operator、Executor 部署排错指南
大数据·后端·apache hive
一直都在5721 小时前
Java死锁
java·开发语言
IT_陈寒1 小时前
深入理解JavaScript:核心原理与最佳实践
前端·人工智能·后端
树獭叔叔1 小时前
GRPO:比PPO更简单的RLHF算法
后端·aigc·openai
shelter1 小时前
并发操作session对象导致登录闪退问题
后端
sthnyph2 小时前
初识MySQL · 库的操作
数据库·mysql
原来是猿2 小时前
MySQL【视图】
数据库·mysql
兆子龙2 小时前
TypeScript高级类型编程:从入门到精通
前端·后端
IT_陈寒2 小时前
Python开发者的效率革命:这5个技巧让你的代码提速50%!
前端·人工智能·后端