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>

去掉单引号即可

相关推荐
twj_one2 小时前
Arthas使用
java
lizz313 小时前
C++模板编程:从入门到精通
java·开发语言·c++
shoubepatien3 小时前
JAVA -- 05
java·开发语言
寰天柚子3 小时前
Java并发编程中的线程安全问题与解决方案全解析
java·开发语言·python
memgLIFE3 小时前
Springboot 分层结构
java·spring boot·spring
shoubepatien4 小时前
JAVA -- 08
java·后端·intellij-idea
kong79069284 小时前
Java新特性-(二)Java基础语法
java·新特性·java 基础语法
yangminlei4 小时前
springboot pom.xml配置文件详细解析
java·spring boot·后端
黄俊懿4 小时前
【深入理解SpringCloud微服务】Seata(AT模式)源码解析——全局事务的提交
java·后端·spring·spring cloud·微服务·架构·架构师
JAVA+C语言4 小时前
String Constant Pool
java·开发语言