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

相关推荐
tianyu2344 分钟前
双指针循环匹配金额——打款记录与账单的自动对账算法
java·算法·双指针循环·匹配金额
YDS8299 分钟前
大营销平台 —— 架构解析和抽奖流程串联
java·springboot·ddd
小贤plus14 分钟前
MyBatis‑Plus IPage 分页踩坑实战:分页与全量查询兼容方案
java
用户81818706274616 分钟前
第30章 Web 层与事务异常:参数校验、@Transactional 失效场景全集
后端
Java内核笔记19 分钟前
BeanRegistrar:Spring Boot 4 最被低估的新特性,彻底改变 Bean 注册方式
java·后端
还是鼠鼠24 分钟前
【Spring AI智能体实战 02】Spring Boot 3.4整合Spring AI:项目创建与依赖配置
java·人工智能·spring boot·maven·spring ai
用户81818706274625 分钟前
第28章 RPC 框架异常:Dubbo / gRPC
后端
搬砖小匠40 分钟前
SpringBoot 通过自定义注解 + AOP 实现数据字典自动翻译(通用方案)
java·后端
今天AI了吗41 分钟前
【AI智能体】Hermes Agent 从部署到项目实战操作详解
java·人工智能·python·milvus