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>

去掉单引号即可

相关推荐
码出财富7 小时前
SpringBoot 内置的 20 个高效工具类
java·spring boot·spring cloud·java-ee
我是小疯子667 小时前
Python变量赋值陷阱:浅拷贝VS深拷贝
java·服务器·数据库
森叶8 小时前
Java 比 Python 高性能的原因:重点在高并发方面
java·开发语言·python
二哈喇子!8 小时前
Eclipse中导入外部jar包
java·eclipse·jar
微露清风8 小时前
系统性学习C++-第二十二讲-C++11
java·c++·学习
进阶小白猿8 小时前
Java技术八股学习Day20
java·开发语言·学习
gis开发8 小时前
【无标题】
java·前端·javascript
Wpa.wk8 小时前
性能测试 - 搭建线上的性能测试环境参考逻辑图
java·经验分享·测试工具·jmeter·性能测试
代码村新手9 小时前
C++-类和对象(中)
java·开发语言·c++
葵花楹9 小时前
【JAVA课设】【游戏社交系统】
java·开发语言·游戏