一直使用MybatisPlus,好久没写Mybatis 了,都差点忘了foreach 标签怎么使用了,备忘保存下,
下面是一个根据 id 的集合批量删除的方法。
Mapper 中的方法定义如下:
Integer batchDeleteByIds(@Param("userId")String userId,@Param("ids")List<String> ids);
xml 中的:
<delete id="batchDeleteByIds">
DELETE FROM article WHERE user_id = #{userId,jdbcType=VARCHAR}
and id IN
<foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
#{item,jdbcType=VARCHAR}
</foreach>
</delete>
OK...