软件编程
位置:首页>> 软件编程>> java编程>> 如何在mapper文件中使用in("str1","str2")

如何在mapper文件中使用in("str1","str2")

作者:懒惰的小蜗牛  发布时间:2023-07-10 10:40:51 

标签:mapper,in,str1,str2

mapper文件使用in("str1","str2")

mybatis的xxxMapper.xml文件中,如果筛选的字段使用的是varchar类型,在xml中需要对遍历做处理,在遍历的字段外加‘’

xml

select * from table_name
<where>
    del_flg = 1
    <if test="statuses != null and statuses.size() > 0 ">
        and status in
        <foreach collection="statuses" close=")" open="(" item="item" separator=",">
            -- 此处添加单引号
            '${item}'
        </foreach>
    </if>
</where>

小细节记录下来,方便后续查看 

mapper.xml中sql使用 in 执行失败的原因

mapper.xml传参如果下

user_obj_id in ( #{ids})

最终执行的sql拼接如下

user_obj_id in ( ‘55,56,57' )

而不是期望的

user_obj_id in ( ‘55',‘56',‘58' )

如何在mapper文件中使用in("str1","str2")

来源:https://blog.csdn.net/qq_41070393/article/details/81484949

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com