本文最后更新于 2026年5月29日 晚上
获取通知详情信息接口的实现
获取通知详情信息接口的需求
根据通知id 查询通知详情
回填发布人名称
代码实现
在 NoticeController 中添加接口
1 2 3 4 5 6 7 8 9 10
| @GetMapping("/{id}/detail") @SystemLog(businessName = "获取通知详情信息(用户查看通知信息时用上)") @ApiOperation(value = "获取通知详情信息", notes = "获取通知详情信息,用户查看通知时用", response = NoticeFormDetailVo.class) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "友链id", dataType = "long", paramType = "path") }) public ResponseResult<NoticeDetailVo> getNoticeDetail(@PathVariable Long id) { return sysNoticeService.getNoticeDetail(id); }
|
创建 NoticeDetailVo
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 36
| @Data @AllArgsConstructor @NoArgsConstructor @Accessors(chain = true) @ApiModel(description = "通知详情信息响应对象") public class NoticeDetailVo { @ApiModelProperty(value = "通知id", example = "6") private Long id;
@ApiModelProperty(value = "通知标题", example = "这里是标题") private String title;
@ApiModelProperty(value = "通知内容", example = "这里是内容") private String content;
@ApiModelProperty(value = "通知类型(关联字典编码:notice_type)", example = "系统维护") private Integer type;
@ApiModelProperty(value = "通知等级(字典code:notice_level)", example = "M") private String level;
@ApiModelProperty(value = "状态(0: 未发布, 1: 已发布, 2: 已撤回)", example = "1") private String status;
@ApiModelProperty(value = "目标人ID集合(多个使用英文逗号,分割)", example = "['1', '23']") private List<Long> targetUserIds;
@TableField(exist = false) @ApiModelProperty(value = "发布人名称", example = "云梦泽") private String publisherName;
@TableField(fill = FieldFill.INSERT_UPDATE) @ApiModelProperty(value = "发布时间", example = "2024-01-01 12:00:00") private Date publishTime; }
|
在 NoticeServiceImpl 中
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<NoticeDetailVo> getNoticeDetail(Long id) { SysNotice notice = sysNoticeService.getById(id); if (notice == null) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "该通知不存在!"); }
NoticeDetailVo noticeDetailVo = BeanCopyUtils.copyBean(notice, NoticeDetailVo.class);
if (notice.getPublisherId() != null) { SysUser publisher = sysUserService.getById(notice.getPublisherId()); if (publisher != null) { noticeDetailVo.setPublisherName(StringUtils.hasText(publisher.getNickname()) ? publisher.getNickname() : publisher.getUsername()); } }
return ResponseResult.okResult(noticeDetailVo); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/