首页 > 其他分享 >mybatis中in的坑

mybatis中in的坑

时间:2023-01-06 18:11:49浏览次数:53  
标签:遍历 传入 item 字符串 数组 mybatis

在mybatis的in查询分为三种传入参数

1、string 字符串传入,以逗号分割:优点:简单方便,高效,缺点:不能防止sql注入,

注意,传入的参数为字符串,如('A123','B123','C123')需要提前把数据封装好

<foreach item="item" index="index" collection="codes.split(',')" open="(" separator="," close=")">
#{item}
</foreach>

in (${item})

 

2、list 集合传入,在in条件中使用,遍历集合

<foreach item="item" index="index" collection="codeList" open="(" close=")" separator=","> 

    #{item}

</foreach>

3、array数组传入,在in条件中使用,遍历数组

<foreach collection="codeArray" item="item" separator="," open="(" close=")">

#{item}

</foreach>

 

标签:遍历,传入,item,字符串,数组,mybatis
From: https://www.cnblogs.com/lqh969696/p/17030975.html

相关文章