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

相关推荐
tb_first1 分钟前
SSM速通4
java·jvm·spring·tomcat·maven·mybatis
梦梦代码精8 分钟前
开源、免费、可商用:BuildingAI一站式体验报告
开发语言·前端·数据结构·人工智能·后端·开源·知识图谱
百炼成神 LV@菜哥15 分钟前
Kylin Linux V10 aarch64安装DBeaver
java·linux·服务器·kylin
程可爱22 分钟前
springboot整合mybatis和postgresql
spring boot·postgresql·mybatis
有代理ip30 分钟前
成功请求的密码:HTTP 2 开头响应码深度解析
java·大数据·python·算法·php
小天源1 小时前
银河麒麟 V10(x86_64)离线安装 MySQL 8.0
android·mysql·adb·麒麟v10
好好沉淀1 小时前
ES 脚本核心语法:ctx._source [‘group_id‘]
java·elasticsearch·script
李慕婉学姐1 小时前
【开题答辩过程】以《基于Spring Boot的疗养院理疗管理系统的设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
java·spring boot·后端
risc1234561 小时前
【Elasticsearch】LeafDocLookup 详述
大数据·elasticsearch·mybatis
tb_first1 小时前
SSM速通2
java·javascript·后端