1. 程式人生 > >spring mvc接收陣列mybatis 接收批量刪除程式碼

spring mvc接收陣列mybatis 接收批量刪除程式碼

頁面接收引數

//批量刪除的操作
function optDelete(){
//校驗,至少選擇一個
var size = $("input[name =ids]:checked").size();
if(size==0){
alert("請至少選擇一個");
return ;
}


if(!confirm("你確認刪除嗎")){
return ;
}




//上傳
$("#jvForm").attr("action","/brand/delete.do");
$("#jvForm").attr("method","post");
$("#jvForm").submit();
}

controller接收引數

@RequestMapping(value="/brand/delete.do")
public String deleteBrands(Long[] ids){

brandService.deleteBrands(ids);
return "redirect:/brand/list.do";
}

mybatissql操作

 <delete id="deleteBrands" parameterType="Long[]">
delete * from bbs_brand where id (語法錯誤,delete from bbs_brand where id in)
in
<foreach collection="array" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
 
</delete>