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>

去掉单引号即可

相关推荐
编程、小哥哥20 分钟前
netty之Netty与SpringBoot整合
java·spring boot·spring
IT学长编程1 小时前
计算机毕业设计 玩具租赁系统的设计与实现 Java实战项目 附源码+文档+视频讲解
java·spring boot·毕业设计·课程设计·毕业论文·计算机毕业设计选题·玩具租赁系统
莹雨潇潇1 小时前
Docker 快速入门(Ubuntu版)
java·前端·docker·容器
杨哥带你写代码2 小时前
足球青训俱乐部管理:Spring Boot技术驱动
java·spring boot·后端
郭二哈2 小时前
C++——模板进阶、继承
java·服务器·c++
A尘埃2 小时前
SpringBoot的数据访问
java·spring boot·后端
yang-23072 小时前
端口冲突的解决方案以及SpringBoot自动检测可用端口demo
java·spring boot·后端
沉登c2 小时前
幂等性接口实现
java·rpc
代码之光_19802 小时前
SpringBoot校园资料分享平台:设计与实现
java·spring boot·后端
科技资讯早知道3 小时前
java计算机毕设课设—坦克大战游戏
java·开发语言·游戏·毕业设计·课程设计·毕设