本文最后更新于 2026年4月23日 晚上
修改友链接口的实现
修改友链接口的需求
根据标签id获得旧的友链信息
检查友链站点地址是否除了自己外与其他的重复
如果是除了和自己以外的其他站点地址重复则不允许更新
更新分友链信息
代码实现
创建 UpdateLinkDto 请求对象
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
|
@Data @AllArgsConstructor @NoArgsConstructor @ApiModel(description = "更新友链请求对象") public class UpdateLinkDto {
@ApiModelProperty(value = "友链ID", required = true, example = "1") private Long id;
@ApiModelProperty(value = "站点名称", example = "云梦泽的个人博客") private String name;
@ApiModelProperty(value = "个人描述", example = "这里是云梦泽的个人博客") private String description;
@ApiModelProperty(value = "站点地址", required = true, example = "https://hgt12.github.io") private String address;
@ApiModelProperty(value = "头像地址", example = "https://hgt12.github.io/img/mi_manchi.png") private String logo;
@ApiModelProperty(value = "排序", example = "1") private Integer sort;
@ApiModelProperty(value = "状态(0-正常,1-禁用)", example = "0") private String status; }
|
在 AdminLinkServiceImpl 中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
@Override public ResponseResult updateLink(Long id, UpdateLinkDto updateLinkDto) { updateLinkDto.setId(id);
LambdaQueryWrapper<Link> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Link::getAddress, updateLinkDto.getName()) .ne(Link::getId, id); long count = linkService.count(queryWrapper);
if (count > 0) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "站点地址已存在,请修改后重试!"); }
Link link = BeanCopyUtils.copyBean(updateLinkDto, Link.class); linkService.updateById(link);
return ResponseResult.okResult(); }
|
最后测试接口成功
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/