欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

MyBatis 学习总结 (10) - 批量操作

最编程 2024-05-07 17:31:12
...

批量删除:

 <delete id= "deleteBatchByXXX" parameterType= "list">

       delete from 表名 where groupon_id in

       <foreach collection="list" item= "item" index ="index"

            open= "(" close =")" separator=",">

            #{item}

       </foreach >

       </delete >

注意,foreach是循环,用来读取传入的list参数。批量处理是parameterType的类型必须要注意。foreach标签中的collection属性表示传入的是什么集合类型。item表示的是集合中的一个量类似于

List<String>list;

for(String str:list){

     ……

}

item就相当于str的作用,用来遍历collection。index就是集合的索引。open表示标签以什么开始,close表示标签以什么结束。seprator表示元素之间的间隔。