关于 mapper.xml 中 sql使用 in 执行无效的原因

1.SQL

xml 复制代码
	<select id="getList" resultType="com.xxx.xxx.front.response.ConvertList">
        select
        	*
        from
        	store_product
        where
        	1=1
        <if test="cateIdList != null">
            and cate_id in
            <foreach collection="cateIdList" item="cateIdList" index="index" open="(" separator="," close=")">
                #{cateIdList}
            </foreach>
        </if>
    </select>

2.最终执行的sql拼接如下

  and cate_id in ('753','753')

3.解决方案

  in ('753','753') 这样的sql在数据库执行之后是查不到任何数据的,即便cate_id本身的确是字符串也是一样。in()不能比较字符,如果要比较字符还是得使用like或者or。所以只能将入参改成 Integer 最终拼接为 in (753,753) 才能查出数据

相关推荐
睡不醒男孩0308234 小时前
第二篇:深入探索开源数据库高可用:构建基于CLup的PostgreSQL生产级高可用与读写分离架构
数据库·postgresql·开源·clup
xieliyu.6 小时前
Java算法精讲:双指针(三)
java·开发语言·算法
明夜之约6 小时前
Spring Boot 自动装配源码
java·spring boot·后端
Leaton Lee6 小时前
Spring Boot分层架构详解:从Controller到Service再到Mapper的完整流程
java·spring boot·后端·架构
Micro麦可乐6 小时前
Spring Boot 实战:从零设计一个短链系统(含完整代码与数据库设计)
数据库·spring boot·后端·哈希算法·雪花算法·短链系统
Jinkxs6 小时前
Resilience4j- 与 Spring Boot 快速集成:自动配置与基础注解使用
java·spring boot·后端
辣机小司6 小时前
【踩坑记录:Spring Boot 配置文件读取值不一致?警惕 YAML 的“八进制陷阱”与 SnakeYAML 版本之谜】
java·spring boot·后端·yaml·踩坑记录
码农阿豪7 小时前
从零到一:Spring Boot快速接入金仓数据库实战
数据库·spring boot·后端
鼎讯信通7 小时前
风电光缆运维提质增效:G-4000A 光缆故障追踪仪破解风场巡检难题
运维·网络·数据库
三十..7 小时前
MySQL 从入门到高可用架构实战精要
运维·数据库·mysql