测试代码
@Test
public void deleteBookByIds(){
/*List<Long> ids = new ArrayList<>();
ids.add(8L);
ids.add(10L);
ids.add(12L);
ids.add(14L);*/
Long[] ids = {9L,11L,13L,15L};
session.delete("com.ss.dao.BookMapper.deleteBookByIds", ids);
}
mapper映射文件,namespace为com.ss.dao.BookMapper
<delete id="deleteBookByIds" parameterType="java.lang.Long">
delete from t_book where book_id in
<!-- <foreach collection="list" item="id" open="(" close=")" separator="," > -->
<foreach collection="array" item="id" open="(" close=")" separator="," >
#{id}
</foreach>
</delete>
其中传入的参数为集合是,<foreach>标签的collection的值为list,传入的参数为数组时,collection的值为array!