仿牛客网社区项目(十三)帖子详情

帖子详情

  • DiscussPostMapper

  • DiscussPostService

  • DiscussPostController

  • index.html

    • 在帖子标题上增加访问详情页面的链接
  • discuss-detail.html

    • 处理静态资源的访问路径
    • 复用index.html的header区域
    • 显示标题、作者、发布时间、帖子正文等内容

根据帖子的主键id查询贴子的详情内容。

DiscussPostMapper接口#

DiscussPost selectDiscussPostById(int id);

discusspost-mapper.xml

<select id="selectDiscussPostById" resultType="DiscussPost">
    select <include refid="selectFields"></include>
    from discuss_post
    where id = #{id}
</select>

DiscussPostService#

public DiscussPost findDiscussPostById(int id) {
    return discussPostMapper.selectDiscussPostById(id);
}

DiscussPostController#

@RequestMapping(path = "/detail/{discussPostId}", method = RequestMethod.GET)
public String getDiscussPost(@PathVariable("discussPostId") int discussPostId, Model model) {
    // 帖子
    DiscussPost post = discussPostService.findDiscussPostById(discussPostId);
    model.addAttribute("post", post);
    // 作者
    User user = userService.findUserById(post.getUserId());
    model.addAttribute("user", user);

    return "/site/discuss-detail";
}

index.html,改超链接。| |是常量和变量拼接的。取帖子主键用${map.post.id}

th:href="@{|/discuss/detail/${map.post.id}|}"

discuss-detail.html,改动态标题、头像、用户名、发帖时间、帖子内容

th:utext="${post.title}"
th:src="${user.headerUrl}"
th:utext="${user.username}"
th:text="${#dates.format(post.createTime,'yyyy-MM-dd HH:mm:ss')}"
th:utext="${post.content}"
posted @   卷皇  阅读(327)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示
主题色彩