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>

去掉单引号即可

相关推荐
海边的Kurisu1 小时前
苍穹外卖日记 | Day1 苍穹外卖概述、开发环境搭建、接口文档
java
C雨后彩虹5 小时前
任务最优调度
java·数据结构·算法·华为·面试
heartbeat..5 小时前
Spring AOP 全面详解(通俗易懂 + 核心知识点 + 完整案例)
java·数据库·spring·aop
Jing_jing_X5 小时前
AI分析不同阶层思维 二:Spring 的事务在什么情况下会失效?
java·spring·架构·提升·薪资
元Y亨H7 小时前
Nacos - 服务发现
java·微服务
微露清风7 小时前
系统性学习C++-第十八讲-封装红黑树实现myset与mymap
java·c++·学习
dasi02277 小时前
Java趣闻
java
阿波罗尼亚8 小时前
Tcp SSE Utils
android·java·tcp/ip
susu10830189118 小时前
springboot3.5.8整合minio8.5.9
java·springboot
不知道累,只知道类8 小时前
深入理解 Java 虚拟线程 (Project Loom)
java·开发语言