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

相关推荐
孪生质数-4 小时前
MySQL主从延迟根因诊断法
数据库·mysql
WiChP5 小时前
【V0.1B5】从零开始的2D游戏引擎开发之路
java·服务器·数据库
cch89185 小时前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神6 小时前
拉链表概念与基本设计
java·开发语言·数据库
cch89186 小时前
汇编与Go:底层到高层的编程差异
java·汇编·golang
chushiyunen6 小时前
python中的@Property和@Setter
java·开发语言·python
禾小西6 小时前
Java中使用正则表达式核心解析
java·python·正则表达式
2401_895521346 小时前
SpringBoot Maven快速上手
spring boot·后端·maven
yoyo_zzm6 小时前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python