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

相关推荐
立莹Sir1 小时前
Spring Bean 生命周期详解
java·python·spring
uElY ITER1 小时前
Spring全家桶简介
java·后端·spring
lay_liu7 小时前
springboot 文件下载
java·spring boot·后端
Flittly7 小时前
【SpringAIAlibaba新手村系列】(11)Embedding 向量化与向量数据库
java·笔记·spring·ai·springboot
workflower8 小时前
AI制造-推荐初始步骤
java·开发语言·人工智能·软件工程·制造·需求分析·软件需求
J超会运8 小时前
OpenEuler系统MySQL故障排查终极指南
mysql
ACGkaka_9 小时前
SimpleDateFormat 线程安全问题及修复方案
java·jvm·安全
leo_messi949 小时前
多线程(五) -- 并发工具(二) -- J.U.C并发包(八) -- CompletableFuture组合式异步编程
android·java·c语言
m0_3801138410 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring