mybatis 批量删除数据
程序员文章站
2022-06-03 08:01:44
...
mybatis
批量删除数据,将需要删除的数据id
存放到list
中,将list
作为参数传递,具体代码如下:
1、在mapper层中创建deleteAudioAudioFiles
(@Param(“ids”)List ids) 方法,返回删除的数据条数
package com.center.manager.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.center.manager.bean.Audio;
@Mapper
public interface AudioMapper {
int deleteAudioAudioFiles(@Param("ids")List<String> ids); //批量删除数据
}
2、mybatis的xml文件中的delete语句如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.center.manager.mapper.AudioMapper">
<delete id="deleteAudioAudioFiles">
delete from
t_audio
where audio_file in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id,jdbcType=VARCHAR}
</foreach>
</delete>
</mapper>