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>

去掉单引号即可

相关推荐
码农颜8 小时前
5.4.1 锁分类
java·数据库·mysql
linux-hzh9 小时前
百日算法修炼 · Day 03
java·算法
不负岁月无痕10 小时前
简单理解操作系统结构
java·linux·c语言·开发语言·c++·面试
mister_guo10 小时前
Java线程池参数应该如何设置(ThreadPoolExecutor)
java
余额瞒着我当琳10 小时前
C++模板初阶与STL初探
android·java·c++
淡海水10 小时前
15-02-YooAsset面试篇-Unity架构设计与源码
java·unity·面试·c#·游戏引擎·yooasset
qq_4480111611 小时前
C语言中的指针函数和函数指针
java·c语言·开发语言
weixin_BYSJ198711 小时前
springboot酒店管理系统--附源码27436
java·spring boot·python·随机森林·贪心算法·eclipse·django
2401_8949155311 小时前
GEO 源码部署如何实现精准地域分发?核心配置参数深度讲解
java·运维·服务器·后端·开源
evans在进步13 小时前
LeetCode 2 两数相加:链表模拟加法,Java 图解进位过程
java·leetcode·链表