Controller方法:
@ApiOperation(value = "删除留言")
@PostMapping("/del")
public CommonResult delMessage(Long id) {
if (ObjectUtil.isEmpty(id)) {
return CommonResult.failed("参数为空");
}
return busLeaveMessageService.delMessage(id) ? CommonResult.success(id, "留言删除成功") : CommonResult.failed("留言删除失败");
}
serviceImpl:
public Boolean delMessage(Long id) {
// 删除本身
boolean self = this.removeById(id);
// 删除自己下面的回复
QueryWrapper<BusLeaveMessage> wrapper = new QueryWrapper<BusLeaveMessage>();
wrapper.eq("pid", id);
boolean children = this.remove(wrapper);
return self && children;
}
删除操作,需要传入的是留言的id,在删除了留言本身时,要注意删除留言下的回复,回复的pid正是留言的id;最后return self && children;
确保全部都删除了