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 天前
SpringBoot 扫码登录全流程:UUID 生成、状态轮询、授权回调详解
java·spring boot·后端
a努力。1 天前
国家电网Java面试被问:Spring Boot Starter 制作原理
java·spring boot·面试
一 乐1 天前
酒店预约|基于springboot + vue酒店预约系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端
一灰灰1 天前
开发调试与生产分析的利器:MyBatis SQL日志合并插件,让复杂日志秒变可执行SQL
chrome·后端·mybatis
guslegend1 天前
Tomact高级使用及原理剖析
java
Code blocks1 天前
SpringBoot从0-1集成Minio对象存储
java·spring boot·后端
故渊ZY1 天前
MyBatis事务原理与实战指南
java·mybatis
HTouying1 天前
线程池【工具类】
java
深盾科技1 天前
融合C++与Python:兼顾开发效率与运行性能
java·c++·python