MySQL效果:
DELETE FROM attachment_table WHERE logid = '24' AND NAME IN ('policycustom1.xmlx','policycustom.xmlx','policycustom1.xmlx','policycustom.xmlx');
Mybatis:
void deleteByLogIdAndNames(@Param("logid") Integer logID, @Param("names") String[] names);
<delete id="deleteByLogIdAndNames"> delete from attachment_table where logid = #{logid,jdbcType=INTEGER} AND NAME IN <foreach collection="names" item="item" index="index" open="(" close=")" separator=","> #{item, jdbcType=LONGVARCHAR} </foreach> </delete>
我开始是如下写:这种方式无法达到上面MySQL的效果
<delete id="deleteByLogIdAndNames"> delete from attachment_table where logid = #{logid,jdbcType=INTEGER} AND NAME IN <foreach collection="names" item="item" index="index" open="(" close=")" separator=","> #item </foreach> </delete>