微服务 教程
1085个小节阅读:195.7k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
<foreach>
类似JAVA中的for循环,可以遍历集合或数组。<foreach>
有如下属性:
我们使用<foreach>
遍历数组进行批量删除。
持久层接口添加方法
xxxxxxxxxx
void deleteBatch(int[] ids);
映射文件添加标签
xxxxxxxxxx
<delete id="deleteBatch" parameterType="int">
delete from user
<where>
<foreach open="id in(" close=")" separator="," collection="array" item="id" >
#{id}
</foreach>
</where>
</delete>
编写测试方法
xxxxxxxxxx
@Test
public void testDeleteBatch(){
int[] ids = {9,11};
userMapper.deleteBatch(ids);
session.commit();
}
1. MyBatis的<foreach>
中,使用属性表示遍历的数据类型:
A item
B open
C close
D collection
2. 在MyBatis映射文件中,遍历数组时需要将collection
的值设为:
A array
B set
C list
D map
1=>D 2=>A