批量删除功能

java学习 java学习
📅 2025-08-21 16:33 👤 admin

前端

// 批量删除权限
async deletePermissions(ids: number[]): Promise<void> {
const response = await request.post<ApiResponse<void>>('/permissionAction/batch_delete', {
ids
})
if (response.code !== 200) {
throw new Error(response.message || '批量删除权限失败')
}
},

后端
controller
@PostMapping("/batch_delete")
public R<String> batchDeleteMenus(@RequestBody BatchDeleteDTO dto) {
try {
boolean success = permissionActionService.batchDelete(dto.getIds());
if (success) {
return R.ok("批量删除菜单成功");
} else {
return R.error("批量删除菜单失败");
}
} catch (Exception e) {
return R.error("批量删除菜单失败:" + e.getMessage());
}
}

Service
boolean batchDelete(List<Long> ids);

@Override
public boolean batchDelete(List<Long> ids) {
return permissionActionMapper.deleteBatchIds(ids)>0;
}

mapper
int deleteBatchIds(@Param("ids") List<Long> ids);

XML
<delete id="deleteBatchIds" parameterType="java.util.List">
DELETE FROM permission_action
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>







相关笔记