- 작성 순서
mapper 기능&테스트 -> service 기능&테스트 -> Controller -> View
1-1. RecipeMapper
/* 게시판 조회 */
public RecipeVO getPage(int id);
1-2. RecipeMapper.xml
<!-- 게시판 목록 -->
<select id="getPage" resultType="RecipeVO">
select * from recipe where id = #{id}
</select>
1-3. mapper 테스트하기 - (Run as - Unit Test)
int id = 1;
log.info("" + recipeMapper.getPage(id));
id=1 게시판글이 콘솔창에 나옴
2-1. RecipeService = RecipeMapper
/* 게시판 조회 */
public RecipeVO getPage(int id);
2-2. RecipeServiceImpl
@Override
public RecipeVO getPage(int id) {
return recipeMapper.getPage(id);
}
3. Controller 에서 게시판 조회 페이지 만들기
get매핑 -> get 뷰 페이지 만들기
@GetMapping("/get")
public String recipePageGet(@RequestParam("id") int id, Model model) {
model.addAttribute("board", recipeService.getPage(id));
return "get";
}
4. View 화면
[ get.html ]
<div class="card card-plain">
<div class="card-body bg-white">
<table class="table table-condensed">
<tr>
<th>번호</th>
<td th:text="${board.id}"></td>
<th>작성일</th>
<td th:text="${#temporals.format(board.registerdate, 'yyyy-MM-dd a hh:mm:ss')}"></td>
</tr>
<tr>
<th>작성자</th>
<td th:text="${board.writer}"></td>
<th>수정일</th>
<td th:text="${#temporals.format(board.updateDate, 'yyyy-MM-dd a hh:mm:ss')}"></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3" th:text="${board.title}"></td>
</tr>
<tr>
<th>재료</th>
<td colspan="3" th:text="${board.ingredient}"></td>
</tr>
<tr>
<th>내용</th>
<td colspan="4" th:text="${board.content}"></td>
</tr>
</table>
</div>
<div class="card-footer bg-white text-center pt-0 px-lg-2 px-1">
<a th:href="@{/board/list}" class="btn btn-success">목록</a>
<a th:href="@{/board/update}" class="btn btn-secondary">수정</a>
</div>
</div>
[ recipe_list.html ]
게시판 목록에서 title 클릭시 게시글 조회페이지로 이동하도록 a태그넣기
<a th:href="@{/recipe/board/get(id=${board.id})}">
<span class="text-secondary text-xs" th:text="${board.title}"></span>
</a>
th:href="@{/board/get(bno=${board.bno})}" -> 파라미터를 괄호에 넣는다
= get?id=1
게시글 조회페이지로 이동한 모습
반응형
LIST
'Spring boot | 쇼핑몰 만들기 | 어글리 마켓 > 게시판 만들기' 카테고리의 다른 글
레시피 게시판 목록 만들기 (0) | 2022.05.15 |
---|---|
게시판 등록 (0) | 2022.05.15 |
레시피 게시판 만들기 (0) | 2022.05.15 |