问答平台(3),帖子详情
数据访问层
1 |
|
- discusspost-mapper.xml 里写sql
1
2
3
4
5
6
7
8
9<sql id="selectFields">
id, user_id, title, content, type, status, create_time, comment_count, score
</sql>
<select id="selectDiscussPostById" resultType="DiscussPost">
select
<include refid="selectFields"></include>
from discuss_post
where id = #{id}
</select>
业务层
1 |
|
表现层
1 |
|
页面
- index.html
1
在帖子标题上增加访问详情页面的链接
1
2
3
4
5
6<!-- 帖子列表 -->
<h6 class="mt-0 mb-3">
<a th:href="@{|/discuss/detail/${map.post.id}|}" th:utext="${map.post.title}">备战春招,面试刷题跟他复习,一个月全搞定!</a>
<span class="badge badge-secondary bg-primary" th:if="${map.post.type==1}">置顶</span>
<span class="badge badge-secondary bg-danger" th:if="${map.post.status==1}">精华</span>
</h6> - discuss-detail.html
1
2
3处理静态资源的访问路径
复用 index.html 的 header 区域
显示标题、作者、发布时间、帖子正文等内容1
2
3
4
5
6
7
8
9
10
11<!-- 帖子详情 -->
<!-- 标题 -->
<span th:utext="${post.title}">备战春招,面试刷题跟他复习,一个月全搞定!</span>
<!-- 作者 -->
<img th:src="${user.headerUrl}" class="align-self-start mr-4 rounded-circle user-header" alt="用户头像">
<div class="mt-0 text-warning" th:utext="${user.username}">寒江雪</div>
发布于 <b th:text="${#dates.format(post.createTime, 'yyyy-MM-dd HH:mm:ss')}">2019-04-15 15:32:18</b>
<!-- 正文 -->
<div class="mt-4 mb-3 content" th:utext="${post.content}">
xxx...
</div>
问答平台(3),帖子详情
https://lcf163.github.io/2020/05/10/问答平台(3),帖子详情/