仿牛客社区项目3.3——帖子详情(普通功能)

在这里插入图片描述
根据帖子的主键id查询贴子的详情内容。
DiscussPostMapper接口

DiscussPost selectDiscussPostById(int id);

discusspost-mapper.xml

<select id="selectDiscussPostById" resultType="DiscussPost">select <include refid="selectFields"></include>from discuss_postwhere 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}"


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部