#9 : 글쓴이 표시
01. 질문 목록
- question_list.html 테이블 헤더에 글쓴이 추가
<table class="table">
<thead class="table-dark">
<tr class="text-center">
<th>번호</th>
<th style="width:50%">제목</th>
<th>글쓴이</th>
<th>작성일시</th>
</tr>
</thead>
<tbody>
<tr class="text-center" th:each="question, loop : ${paging}">
<td th:text="${paging.getTotalElements - ((paging.number-1) * paging.size) - loop.index}"></td>
<td class="text-center">
<a th:href="@{|/question/detail/${question.id}|}"
th:text="${question.subject}"></a>
<span class="text-danger small ms-2"
th:if="${#lists.size(question.answerList) > 0}"
th:text="${#lists.size(question.answerList)}">
</span>
</td>
<td><span th:if="${question.author != null}" th:text="${question.author.username}"></span></td>
<td th:text="${#temporals.format(question.createDate, 'yyyy-MM-dd HH:mm')}"></td>
</tr>
</tbody>
</table>
* 작성자 정보없이 저장된 이전의 질문들을 author 속성이 없으므로 null이 아닌 경우에만 표시되도록 한다.
02. 질문 상세
- question_detail.html에 글쓴이 추가
<!--질문-->
<h1 class="border-bottom py-2" th:text="${question.subject}"></h1>
<div class="card my-3">
<div class="card-body">
<div class="card-text" style="white-space: pre-line;" th:text="${question.content}"></div>
<div class="d-flex justify-content-end">
<div class="badge bg-light text-dark p-2 text-start">
<div class="mb-2">
<span th:if="${question.author != null}" th:text="${question.author.username}"></span>
</div>
<div th:text="${#temporals.format(question.createDate, 'yyyy-MM-dd HH:mm')}"></div>
</div>
</div>
</div>
</div>
<!--답변의 갯수 표시-->
<h5 class="border-bottom my-3 py-2"
th:text="|${#lists.size(question.answerList)}개의 답변이 있습니다.|"></h5>
<!--답변 반복 시작-->
<div class="card my-3" th:each="answer : ${question.answerList}">
<div class="card-body">
<div class="card-text" style="white-space:pre-line;" th:text="${answer.content}"></div>
<div class="d-flex justify-content-end">
<div class="badge bg-light text-dark p-2 text-start">
<div class="mb-2">
<span th:if="${answer.author != null}" th:text="${answer.author.username}"></span>
</div>
<div th:text="${#temporals.format(answer.createDate, 'yyyy-MM-dd HH:mm')}"></div>
</div>
</div>
</div>
</div>
'T-I-L > [책] 요약&정리' 카테고리의 다른 글
| [점프 투 스프링부트] 3장 SBB 서비스 개발(추천, 앵커) - 2023. 09. 07. (0) | 2023.09.07 |
|---|---|
| [점프 투 스프링부트] 3장 SBB 서비스 개발(수정과 삭제) - 2023. 09. 05. ~ 2023. 09. 06. (0) | 2023.09.05 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(엔티티 변경) - 2023. 09. 01. (0) | 2023.09.01 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(로그인&로그아웃) - 2023. 08. 29. ~ 2023. 08. 30. (0) | 2023.08.29 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(회원가입) - 2023. 08. 28. (0) | 2023.08.28 |
