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>

去掉单引号即可

相关推荐
x***38167 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
S***84887 小时前
SpringSecurity踢出指定用户
java
p***s917 小时前
Spring数据库原理 之 DataSource
java·数据库·spring
adobehu7 小时前
麒麟系统安装jdk17
java·jdk
spencer_tseng7 小时前
java.util.IllegalFormatPrecisionException
java·printf
虹科网络安全7 小时前
艾体宝干货 | Redis Java 开发系列#1 从零开始的环境搭建与实践指南
java·数据库·redis
铅笔侠_小龙虾8 小时前
Arthas 命令
java·jvm
seeyoutlb8 小时前
微服务全局日志处理
java·python·微服务
码界奇点8 小时前
Java Web学习 第15篇jQuery从入门到精通的万字深度解析
java·前端·学习·jquery
雨落秋垣8 小时前
手搓 Java 的用户行为跟踪系统
java·开发语言·linq