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

相关推荐
sheji34165 分钟前
【开题答辩全过程】以 基于springboot的校园失物招领系统为例,包含答辩的问题和答案
java·spring boot·后端
寂静or沉默9 分钟前
2026最新Java岗位从P5-P7的成长面试进阶资源分享!
java·开发语言·面试
卓怡学长10 分钟前
m289在线交友系统
java·spring·tomcat·maven·intellij-idea·hibernate
程序员cxuan14 分钟前
人麻了,谁把我 ssh 干没了
人工智能·后端·程序员
zhglhy2 小时前
Java分库分表技术对比分析
java·分库分表
wuyikeer2 小时前
Spring Framework 中文官方文档
java·后端·spring
豆豆的java之旅2 小时前
软考中级软件设计师 数据结构详细知识点(含真题+练习题,可直接复习)
java·开发语言·数据结构
Victor3562 小时前
MongoDB(61)如何避免大文档带来的性能问题?
后端
Victor3562 小时前
MongoDB(62)如何避免锁定问题?
后端
无心水2 小时前
Java时间处理封神篇:java.time全解析
java·开发语言·python·架构·localdate·java.time·java时间处理