本文最后更新于 2026年5月30日 下午
删除配置接口的实现
删除配置接口的需求
检查配置是否存在
找出不存在的 配置id
根据配置id列表删除配置
缓存里删除配置
代码实现
在 ConfigController 中添加接口
1 2 3 4 5 6 7 8 9
| @DeleteMapping("/{ids}") @PreAuthorize("@ps.hasPermission('sys:config:delete')") @SystemLog(businessName = "删除配置(逻辑删除)") @ApiOperation(value = "删除配置接口(批量逻辑删除)", notes = "删除配置,支持批量删除", response = String.class) @ApiImplicitParam(name = "ids", value = "配置id", dataType = "Long", paramType = "path", required = true) public ResponseResult deleteConfig(@PathVariable Long[] ids) { return adminConfigService.deleteConfig(ids); }
|
在 AdminConfigServiceImpl 中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| @Override public ResponseResult deleteConfig(Long[] ids) { if (ids == null || ids.length == 0) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "请选择要删除的配置"); }
List<Long> idList = List.of(ids);
List<Config> configToDelete = adminConfigService.listByIds(idList); if (configToDelete.size() != ids.length) { Set<Long> existIds = configToDelete.stream() .map(Config::getId) .collect(Collectors.toSet());
List<Long> notExistIds = idList.stream() .filter(id -> !existIds.contains(id)) .toList();
return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "删除失败!!原因:以下配置 id 不存在:" + notExistIds); }
adminConfigService.removeByIds(idList); configToDelete.forEach(config -> redisTemplate.delete(getConfigCacheKey(config.getConfigKey())));
return ResponseResult.okResult(); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/