mybatis postgresql 批量删除

一、需求介绍

 前端是一个列表页面,列表可以进行复选框的选择,后台进行关联表数据的删除。

二、框架介绍

 springboot+mybatis 数据库用的postgresql

三、具体代码(前端js)

1、前端涉及到的代码

//判断选中状态
var ids ="";

$(".checkbox").each(function () {
if($(this).is(':checked'))
ids +=$(this).val() + ",";
});
ids = ids.slice(0,ids.length-1);
//删除
$.ajax({
cache: false,
type: "post",
dataType:'json',
data:{
id:ids,
},
2、逻辑处理层
    Map<String, Object> m = getMaps(req);
log.info("|" + m + "|");
// 获取选中的id
String ids=m.get("id").toString();
//将获取到的选中的列表封装在list中
List<String> list = new ArrayList<String>();
String[] stIds = ids.split(",");
for (String value : stIds){
list.add(value);
}
int row = knowledgeDao.deleteById(list);
3、dao层处理
@Delete("<script>" +
"delete from file_info f USING resource_info k WHERE f.id = k.file_id and k.id in " +
" <foreach collection=\"list\" open=\"(\" close=\")\" separator=\",\" item=\"ids\">#{ids}</foreach>;" +
"</script>")
int deleteById(List<String> ids);

猜你喜欢

转载自www.cnblogs.com/flyShare/p/12320301.html
今日推荐