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>

去掉单引号即可

相关推荐
2401_833269303 小时前
Java网络编程入门
java·开发语言
金銀銅鐵3 小时前
[Java] 如何将 Lambda 表达式对应的类保存到 class 文件中?
java·后端
それども4 小时前
Gradle 构建疑难杂症 Could not find netty-transport-native-epoll-linux-aarch_64.ja
java·服务器·gradle·maven
正儿八经的少年4 小时前
application.yml 系列配置文件作用与区别
java·配置文件
鱼很腾apoc5 小时前
【学习篇】第20期 超详解 C++ 多态:从语法规则到底层原理
java·c语言·开发语言·c++·学习·算法·青少年编程
cheems95275 小时前
[Spring MVC] 统一功能与拦截器实践总结
java·spring·mvc
Full Stack Developme6 小时前
Spring Boot 事务管理完整教程
java·数据库·spring boot
城管不管6 小时前
前后端远程协作
java
青云计划6 小时前
Feed流
java·后端·spring
java1234_小锋7 小时前
String、StringBuilder、StringBuffer的区别?
java·开发语言