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

相关推荐
q***071431 分钟前
Spring Boot 多数据源解决方案:dynamic-datasource-spring-boot-starter 的奥秘(上)
java·spring boot·后端
q***498638 分钟前
Spring Boot 3.4 正式发布,结构化日志!
java·spring boot·后端
沐浴露z3 小时前
【微服务】基本概念介绍
java·微服务
数据皮皮侠3 小时前
区县政府税务数据分析能力建设DID(2007-2025)
大数据·数据库·人工智能·信息可视化·微信开放平台
Z3r4y4 小时前
【代码审计】RuoYi-4.7.3&4.7.8 定时任务RCE 漏洞分析
java·web安全·ruoyi·代码审计
请叫我阿杰4 小时前
Ubuntu系统安装.NET SDK 7.0
数据库·ubuntu·.net
q***82915 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互
Kuo-Teng5 小时前
LeetCode 160: Intersection of Two Linked Lists
java·算法·leetcode·职场和发展
Jooou5 小时前
Spring事务实现原理深度解析:从源码到架构全面剖析
java·spring·架构·事务