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

相关推荐
苏渡苇2 分钟前
Stream.collect() 的花式玩法:Collector.of() 自定义收集器
java·stream·jdk21·collector·jdk8+·自定义收集器
丶小鱼丶5 分钟前
数据结构和算法之【队列】
java·数据结构
我不听你讲话2 小时前
关系型与非关系型数据库视角下的 MySQL:特性解析与 Linux 部署实践
linux·mysql·nosql
波波0073 小时前
ASP.NET MVC 中的返回类型全集详解
后端·asp.net·mvc
菜鸡儿齐3 小时前
Unsafe方法学习
java·python·学习
汤姆yu3 小时前
IDEA接入Claude Code保姆级教程(Windows专属+衔接前置安装)
java·windows·intellij-idea·openclaw·openclasw安装
prince056 小时前
用户积分系统怎么设计
java·大数据·数据库
原来是猿8 小时前
MySQL【内置函数】
数据库·mysql
96778 小时前
理解IOC控制反转和spring容器,@Autowired的参数的作用
java·sql·spring
SY_FC8 小时前
实现一个父组件引入了子组件,跳转到其他页面,其他页面返回回来重新加载子组件函数
java·前端·javascript