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

相关推荐
Drifter_yh5 小时前
【黑马点评】Redisson 分布式锁核心原理剖析
java·数据库·redis·分布式·spring·缓存
鸽鸽程序猿5 小时前
【Redis】zset 类型介绍
数据库·redis·缓存
z玉无心5 小时前
Redis
数据库·redis·oracle
予枫的编程笔记5 小时前
【Redis核心原理篇2】Redis 单线程模型:为什么单线程还能这么快?
数据库·redis·缓存
fengxin_rou5 小时前
一文吃透 Redis 压缩列表、listpack 及哈希表扩容与并发查询
数据库·redis·散列表
一只鹿鹿鹿5 小时前
智慧水利一体化建设方案
大数据·运维·开发语言·数据库·物联网
_codemonster6 小时前
数据库字符集编码问题
android·数据库·oracle
莫寒清6 小时前
Spring MVC:@RequestParam 注解详解
java·spring·mvc
没有医保李先生7 小时前
字节对齐的总结
java·开发语言
xuzhiqiang07248 小时前
MySQL——数据库的操作
数据库·mysql·oracle