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>

去掉单引号即可

相关推荐
BestAns6 小时前
一文带你吃透 Java 反射机制
java·后端
wasp5206 小时前
AgentScope Java 核心架构深度解析
java·开发语言·人工智能·架构·agentscope
2501_916766546 小时前
【Springboot】数据层开发-数据源自动管理
java·spring boot·后端
自在极意功。6 小时前
MyBatis 动态 SQL 详解:从基础到进阶实战
java·数据库·mybatis·动态sql
软件管理系统7 小时前
基于Spring Boot的便民维修管理系统
java·spring boot·后端
百***78757 小时前
Step-Audio-2 轻量化接入全流程详解
android·java·gpt·php·llama
快乐肚皮7 小时前
MySQL递归CTE
java·数据库·mysql·递归表达式
廋到被风吹走7 小时前
【Spring】DispatcherServlet解析
java·后端·spring
廋到被风吹走8 小时前
【Spring】PlatformTransactionManager详解
java·spring·wpf