bug场景记录

项目场景:

mapper.xml文件中sql语句执行失败,显示输入的参数数量不对

问题描述

sql 复制代码
 <select id="page" resultType="com.sky.entity.Employee">
        select * from employee
            <where>
                <if test="name != null and name !=''">
                    and name like concat('%','#{name}','%')
                </if>
            </where>
                 order by create_time desc
    </select>

xml文件出错

原因分析:

当name的输入为中文字符串时,例如 "标准" 二字会导致mybatis无法自动注入name

解决方案:

将xml文件中的sql语句修改为

sql 复制代码
 <select id="page" resultType="com.sky.entity.Employee">
        select * from employee
            <where>
                <if test="name != null and name !=''">
                    and name like concat('%',#{name},'%')
                </if>
            </where>
                 order by create_time desc
    </select>

去掉单引号即可

相关推荐
爱笑的源码基地1 小时前
高并发 Redis 缓存门诊HIS系统源码,含财务统计药房进销存
java·程序·门诊系统·诊所系统·云诊所源码
憧憬成为web高手1 小时前
皮卡丘靶场速通--sql 2
数据库·sql·mybatis
莫逸风3 小时前
【AgentScope 2.0】 0. 学习指南
java·llm·agent·agentscope
z123456789864 小时前
2026最新两款AI编程工具深度对比实测
java·数据库·ai编程
yaoxin5211235 小时前
470. Java 反射 - Member 接口与 AccessFlag
java·开发语言·python
做个文艺程序员5 小时前
Linux第24篇:Java应用监控体系搭建:Prometheus+Grafana可视化运维
java·grafana·prometheus
小钻风33666 小时前
Spring Boot 文件上传详解:深入理解 MultipartFile 的使用与原理
java·开发语言
其美杰布-富贵-李6 小时前
Spring Boot 工程开发全流程说明
java·spring boot·后端
前端双越老师7 小时前
如何以前端视角(非0基础)学 Java ?
java·node.js·全栈
dear_bi_MyOnly7 小时前
【SpringBoot配置文件】
java·spring boot·后端·学习·spring·java-ee·学习方法