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>

去掉单引号即可

相关推荐
zihao_tom9 分钟前
Spring Boot(快速上手)
java·spring boot·后端
hua8722241 分钟前
SpringSecurity之跨域
java
小王不爱笑1321 小时前
G1 GC 的核心基础:Region 模型的补充细节
java·jvm·算法
salipopl1 小时前
Spring 中的 @ExceptionHandler 注解详解与应用
java·后端·spring
LJianK11 小时前
java封装
java·前端·数据库
海海不瞌睡(捏捏王子)1 小时前
C#知识点概要
java·开发语言·1024程序员节
jessecyj2 小时前
SpringBoot详解
java·spring boot·后端
Flittly2 小时前
【SpringAIAlibaba新手村系列】(2)Ollama 本地大模型调用
java·ai·springboot
_MyFavorite_2 小时前
JAVA重点基础、进阶知识及易错点总结(10)Map 接口(HashMap、LinkedHashMap、TreeMap)
java·开发语言
qqty12172 小时前
Spring Boot管理用户数据
java·spring boot·后端