批量操作 两个方法 :
一 :在控制层 批量操作 :
前端按钮获取 id数组 :
后台通过 String[] id 获取到id数组 ,然后遍历数组
在 循环遍历的时候进行 修改或者删除操作 :
例如 : 批量删除
@RequestMapping("/delete")
public String delete(String[] id,HttpServletRequest request) {
int row =0;
if(id.length !=0) {
for (String d : id) {
System.out.println(d+"=========");
row = packingListService.deleteByPrimaryKey(d);
}
}
if(row >0) {
System.out.println("删除成功");
}else {
System.out.println("删除失败");
}
//重定向
return "redirect:/packing/list";
}
二 :在Mapper.xml文件中 操作 :
mapper接口里面的写法 :
int deleteAll(@Param("ids")String id);
@Param("ids") :参数绑定 , 绑定的是 collection.
mapper.xml 中的写法
<delete id="deleteAll">
delete from PACKING_LIST_C where PACKING_LIST_ID in
<foreach collection="ids" item="id" open="(" close=")"
separator=",">
#{id}
</foreach>
</delete>
<foreach collection="ids" item="id" open="(" close=")"
separator=",">
#{id}
</foreach>
</delete>