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

相关推荐
是小蟹呀^3 小时前
Spring Security + JWT 面试题整理
java·jwt·springsecurity
聆听。。花开雨落4 小时前
mybatis的typeHandler 作用
数据库·mybatis
pxzsky5 小时前
PG17数据库安装中分分词插件:pg_jieba
数据库·postgresql·pg_jieba
spencer_tseng5 小时前
Redis + Nacos.bat
java·windows·dos
她说可以呀5 小时前
Redis哨兵
数据库·redis·bootstrap
troyzhxu5 小时前
列表查询的 GraphQL —— 一行代码终结你的 if-else 地狱!
java·springboot·graphql
霸道流氓气质6 小时前
KMS 密钥管理服务(Key Management Service)原理与实践
linux·服务器·数据库
kirs_ur6 小时前
CXL(Compute Express Link)— 内存扩展的未来
服务器·数据库·性能优化
孫治AllenSun6 小时前
【DataX】生产环境搭建DataX集群案例
java·开发语言·jvm