mybatis 批量删除数据

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语句如下:
	
	
	<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>

你可能感兴趣的:(mybatis)