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

相关推荐
大白要努力!15 分钟前
MySQL 8.0 + Navicat 完整操作指南
数据库·mysql
hboot29 分钟前
AI工程师第一课 - Python
前端·后端·python
焦虑的说说1 小时前
秒杀系统设计方案
java
阿正的梦工坊1 小时前
【Rust】12-借用检查器与非词法生命周期
开发语言·后端·rust
云絮.1 小时前
数据库操作
数据库·mysql·算法·oracle
许彰午1 小时前
30_Java Stream流操作全解
java·windows·python
qq_2518364571 小时前
基于java Web网络订餐系统设计与实现 源码文档
java·开发语言·前端
存在的五月雨2 小时前
MyBatis 中,#{} 和 ${}的区别
mybatis
凡人叶枫2 小时前
Effective C++ 条款17:以独立语句将 newed 对象置入智能指针
java·linux·开发语言·c++·算法
飞天狗1112 小时前
零基础JavaWeb入门——第2课:让网页“活”起来 —— JSP是什么?
java·开发语言·前端·后端·web