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

相关推荐
mqcode1 小时前
若依框架做大了怎么办?多模块 Maven 拆分的完整指南
后端
用户40269244819081 小时前
CRMEB Pro 新增后台接口全链路:路由、权限、验证器、返回格式一次讲清
前端·后端
考虑考虑1 小时前
Java实现hmacsha1加密算法
java·后端·java ee
掉鱼的猫2 小时前
Spring Boot → Solon 注解迁移实战指南:一张对照表说清楚
java·spring boot
程序边界2 小时前
lac_agent自愈链路上篇——crontab守护的那些坑与健康检查实战
后端
笨鸟飞不快2 小时前
从 MVC 到 DDD:一次真实的渐进式迁移实录
后端·架构
plainGeekDev2 小时前
广播接收器 → Flow + Lifecycle
android·java·kotlin
程序员威哥2 小时前
C#也能玩转YOLO:工业视觉原生推理方案,零Python依赖
后端
plainGeekDev2 小时前
EventBus → SharedFlow
android·java·kotlin
kfaino2 小时前
你好,我叫 Prompt——其实,你一直在给 AI 写程序
后端·openai·ai编程