Controller:
@RequestMapping("/delectBatchById")
@ResponseBody
public AjaxResult delectBatchById(Integer[] ids) {//传过来的是一个名叫ids的数组
try {
kqXsjlService.delectBatchById(ids);//删除的方法
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return AjaxResult.fail("网络异常");
}
return AjaxResult.success("批量删除成功");
}
mapper.xml:
<delete id="delectBatchById">
DELETE FROM KS_ST WHERE id in
<foreach collection="array" item="ids" open="(" separator="," close=")">
<!-- collection表示类型,数组是array,集合是List,item 是一个变量名,open表示左括号,separator是逗号,close是右括号 -->
#{ids}
</foreach>
</delete>