MyBatis 集合操作语法范例:配合SQL的in关键字

时间:2023-03-09 15:21:53
MyBatis 集合操作语法范例:配合SQL的in关键字

Java语法:

    private String[] tagIds;

MyBatis语法

  <delete id="deleteByIds" parameterType="java.util.List" >
delete from BIZ_USER_TAG_REL
where ID in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</delete> <delete id="deleteByUserIdAndTagIds" parameterType="com.yuanchuangyun.framework.entity.system.UserTagRel" >
delete from BIZ_USER_TAG_REL
where USER_ID = #{userId} AND TAG_ID in
<foreach item="item" index="index" collection="tagIds"
open="(" separator="," close=")">
#{item}
</foreach>
</delete>