关于 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) 才能查出数据

相关推荐
NE_STOP11 小时前
Vide Coding--AI编程工具的选择
java
码云数智-园园12 小时前
C++20 Modules 模块详解
java·开发语言·spring
程序员黑豆12 小时前
JDK 下载安装与配置详细教程
java·前端·ai编程
小宇宙Zz12 小时前
Maven依赖冲突
java·服务器·maven
swordbob12 小时前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
咖啡八杯13 小时前
GoF设计模式——享元模式
java·spring·设计模式·享元模式
十五喵源码网13 小时前
基于springboot2+vue2的租房管理系统
java·毕业设计·springboot·论文笔记
摇滚侠13 小时前
IDEA 创建 Java 项目 手动整合 SSM 框架
java·ide·intellij-idea
源分享13 小时前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Flittly13 小时前
【AgentScope Java新手村系列】(10)实战-多Agent天气助手
java·spring boot·spring