#16 board : article detail - view template (appliy decoupled logic)
This commit is contained in:
@@ -3,6 +3,7 @@ package com.example.board.controller;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,4 +17,11 @@ public class ArticleController {
|
||||
map.addAttribute("articles", List.of());
|
||||
return "articles/index";
|
||||
}
|
||||
|
||||
@GetMapping("/{articleId}")
|
||||
public String article(@PathVariable Long articleId, ModelMap map) {
|
||||
map.addAttribute("article", "article");
|
||||
map.addAttribute("articleComments", List.of());
|
||||
return "articles/detail";
|
||||
}
|
||||
}
|
||||
|
||||
70
board/src/main/resources/templates/articles/detail.html
Normal file
70
board/src/main/resources/templates/articles/detail.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>게시글 페이지</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<header id="header"></header>
|
||||
|
||||
<main>
|
||||
<header>
|
||||
<h1>첫번째 글</h1>
|
||||
</header>
|
||||
|
||||
<aside>
|
||||
<p>Bobby</p>
|
||||
<p><a href="mailto:haerong22@gmail.com">bobby@email.com</a></p>
|
||||
<p><time datetime="2022-08-10T00:00:00">2022-08-10</time></p>
|
||||
<p>#java</p>
|
||||
</aside>
|
||||
|
||||
<section>
|
||||
<p>본문<br><br></p>
|
||||
|
||||
<div>
|
||||
<form>
|
||||
<label for="articleComment" hidden>댓글</label>
|
||||
<textarea id="articleComment" placeholder="댓글 쓰기.." rows="3"></textarea>
|
||||
<button type="submit">쓰기</button>
|
||||
</form>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<div>
|
||||
<time><small>2022-01-01</small></time>
|
||||
<strong>Uno</strong>
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
|
||||
Lorem ipsum dolor sit amet
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div>
|
||||
<time><small>2022-01-01</small></time>
|
||||
<strong>Uno</strong>
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
|
||||
Lorem ipsum dolor sit amet
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<a href="#">이전 글</a>
|
||||
<a href="#">다음 글</a>
|
||||
</nav>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<footer id="footer"></footer>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<thlogic>
|
||||
<attr sel="#header" th:replace="header :: header" />
|
||||
<attr sel="#footer" th:replace="footer :: footer" />
|
||||
</thlogic>
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>게시판 페이지</title>
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<body>
|
||||
|
||||
<header th:replace="header :: header"></header>
|
||||
<header id="header"></header>
|
||||
|
||||
<main>
|
||||
<form>
|
||||
@@ -70,7 +70,7 @@
|
||||
</nav>
|
||||
</main>
|
||||
|
||||
<footer th:replace="footer :: footer"></footer>
|
||||
<footer id="footer"></footer>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
5
board/src/main/resources/templates/articles/index.th.xml
Normal file
5
board/src/main/resources/templates/articles/index.th.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<thlogic>
|
||||
<attr sel="#header" th:replace="header :: header" />
|
||||
<attr sel="#footer" th:replace="footer :: footer" />
|
||||
</thlogic>
|
||||
@@ -35,7 +35,6 @@ class ArticleControllerTest {
|
||||
;
|
||||
}
|
||||
|
||||
@Disabled("구현 중")
|
||||
@DisplayName("[view][GET] 게시글 상세 페이지 - 정상 호출")
|
||||
@Test
|
||||
public void givenNothing_whenRequestingArticleView_thenReturnsArticleView() throws Exception {
|
||||
@@ -44,7 +43,7 @@ class ArticleControllerTest {
|
||||
// when & then
|
||||
mockMvc.perform(get("/articles/1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.TEXT_HTML))
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
|
||||
.andExpect(view().name("articles/detail"))
|
||||
.andExpect(model().attributeExists("article"))
|
||||
.andExpect(model().attributeExists("articleComments"))
|
||||
@@ -60,7 +59,7 @@ class ArticleControllerTest {
|
||||
// when & then
|
||||
mockMvc.perform(get("/articles/search"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.TEXT_HTML))
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
|
||||
.andExpect(view().name("articles/search"))
|
||||
;
|
||||
}
|
||||
@@ -74,7 +73,7 @@ class ArticleControllerTest {
|
||||
// when & then
|
||||
mockMvc.perform(get("/articles/search-hashtag"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.TEXT_HTML))
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
|
||||
.andExpect(view().name("articles/search-hashtag"))
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user