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>

去掉单引号即可

相关推荐
文丑颜不良啊1 小时前
LeetCode2761~2780题目解析
java·leetcode
IT枫斗者枫哥1 小时前
子线程断言失败,JUnit 为什么还显示通过?
java·后端
考虑考虑4 小时前
JDK27中的Set.ofLazy
java·后端·java ee
文丑颜不良啊4 小时前
LeetCode2841~2860题目解析
java·leetcode
小南家的青蛙4 小时前
Tomcat与Jetty深度对比
java·tomcat·jetty
乌暮5 小时前
Spring AOP 与 Spring 事务:用大白话彻底理解原理与实践
java·数据库·spring boot·后端·sql·学习·spring
YDS8295 小时前
Small Spring IOC篇:容器事件及其监听器
java·spring
金銀銅鐵6 小时前
带您看懂字节码指令(三):一行加法里有什么
java·jvm
文丑颜不良啊6 小时前
LeetCode2921~2940题目解析
java·leetcode
北漂人Java7 小时前
基于 Spring AI Alibaba WorkFlow 构建 Java 生产级 AI Agent
java·人工智能·spring