SSM框架实现批量删除操作

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>

猜你喜欢

转载自blog.csdn.net/baidu_41660182/article/details/87711827