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 分钟前
Java数组的定义、操作与应用场景
java·开发语言
Aileen_0v01 分钟前
【数据结构中链表常用的方法实现过程】
java·开发语言·数据结构·算法·链表·动态规划·csdn开发云
Andy Dennis24 分钟前
一文认识Java常见集合
java·开发语言
w***298534 分钟前
MySQL 创建新用户及授予权限的完整流程
数据库·mysql
weed00041 分钟前
MySQL官网驱动下载(jar包驱动和ODBC驱动)【详细教程】
数据库·mysql
dc_00121 小时前
MySQL无法连接到本地localhost的解决办法2024.11.8
数据库·mysql·adb
mqffc1 小时前
Linux(CentOS)安装 MySQL
linux·mysql·centos
玹外之音2 小时前
Spring AI 实战:手把手教你构建支持多会话管理的智能聊天服务
java·spring
q***76562 小时前
MySQL 中如何进行 SQL 调优
android·sql·mysql
hzc09876543212 小时前
MySQL大小写敏感、MySQL设置字段大小写敏感
数据库·mysql