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 小时前
苍穹外卖--day08
java·数据库·spring boot·mybatis·notepad++
lierenvip1 小时前
SQL 建表语句详解
java·数据库·sql
kuntli1 小时前
Spring Bean生命周期全解析
java
ok_hahaha1 小时前
java从头开始-苍穹外卖-day06-微信小程序开发-微信登录和商品浏览
java·微信·微信小程序·小程序
Java面试题总结1 小时前
Spring @Validated失效?原因、排查与高效解决方案全解析
java·spring boot·spring
剑锋所指,所向披靡!2 小时前
MySQL数据的增删改查
java·数据库·mysql
Villiam_AY2 小时前
一次 DNS 端口引发的代理网络和公司内网冲突问题
java·服务器·数据库
dgvri2 小时前
比较Spring AOP和AspectJ
java
eggwyw2 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
于先生吖3 小时前
国际版JAVA婚恋交友系统源码:多语言适配,可商用的跨境婚恋解决方案
java·大数据·交友