Mybatis中动态SQL使用foreach遍历

在之前数据库中用sql语句批量删除的操作

  

使用sql多条删除语句delete from person where name in ('a','b');

现在改用mybatis中批量数据库语句删除

	<delete id="deletePerson">
	delete from person where name in 
	<foreach collection="nameList" open="(" item="nameItem" close=")" separator=",">
	#{nameItem}
	</foreach>
关键字 使用 解释
collection collection=”nameList” 参数是跟一个集合,这里的 nameList 就是需要遍历的集合
open open=”(“ foreach 遍历开始拼接的字符串
close close=”)” foreach 遍历结束拼接的字符串
separator separator=”,” 遍历 item 之间的分割符
item item=”type” 遍历后 item 的名字

猜你喜欢

转载自blog.csdn.net/linlinlinfeng/article/details/81217517
今日推荐