글 상세보기 링크를 /board/${board.id}
추가
<c:forEach var="board" items="${boards.content}">
<div class="card">
<div class="card-body">
<h4 class="card-title">${board.title}</h4>
<p class="card-text">${board.content}</p>
<p class="card-text">${board.createDate }</p>
<p class="card-text">${board.user.username }</p>
<a href="/board/${board.id}" class="btn btn-dark">상세보기</a>
</div>
</div>
</c:forEach>
boardView() 글 상세보기 메서드 추가
// 글 상세보기
@GetMapping("/board/{id}")
public String findById(@PathVariable int id, Model model) {
model.addAttribute("board", boardService.boardView(id));
return "board/detail";
}
//글 상세보기
@Transactional(readOnly=true)
public Board boardView(int id) {
return boardRepository.findById(id)
.orElseThrow(()->{
return new IllegalArgumentException("글 상세보기실패: 아이디를 찾을 수 없습니다");
});
}
이제 detail페이지를 생성 !
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../layout/header.jsp" %>
<div class="container" style="min-height:450px;">
<div class="form-group">
<h3>${board.title}</h3>
</div>
<div class="form-group">
<div>
${board.content}
</div>
</div>
<button onclick="history.back()" class="btn btn-secondary">목록</button>
<button id="btn-update" class="btn btn-warning">수정</button>
<button id="btn-delete" class="btn btn-danger">삭제</button>
</div>
<script src="/js/board.js"></script>
<%@ include file="../layout/footer.jsp" %>