Spring Boot/기초 게시판제작 + maria DB
JPA를 사용한 게시판 만들기(3) 상세보기작업 {타임리프,스프링부트}
seogi8574
2022. 5. 5. 20:13
반응형
저번에는 리스트를 만들어 보았다 이번에는 상세보기를 알아보도록 하쟈
오늘도 디자인은 물논 없다.
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <!-- 위에 xmlns 하면 타임리프 문법을 쓸수 있다.-->
<head>
<meta charset="UTF-8">
<title>게시글 상세페이지</title>
</head>
<body>
<h1 th:text="${board.title}">제목 입니다.</h1>
<p th:text ="${board.content}">내용이 들어갈 내용입니다.</p>
</body>
</html>
정말 간단하게 제목 H1 태그
내용이 들어가는 p 태그 이다.
<a th:text="${board.title}" th:href="@{/board/view(id=${board.id})}"></a>
컨트롤러 에서 위에 파라미터를 받을 수 있다.
@GetMapping("/board/view")
public String boardView(Model model , Integer id){
model.addAttribute("board",boardService.boardView(id));
return "boardview";
}
먼저 게시물 번호를 파라미터로 받고 그글 을 보여준다.
그 다음에 service를 보자
// 특정 게시글 불러오기
public Board boardView(Integer id){
return boardRepository.findById(id).get();
}
게시글을 불러 와야 하기 떄문에 board타입으로 객체를 만들고
id를 받아준다.
그리고 findById(id) 로 한개의 게시물을 가져 와준다.
select
board0_.id as id1_0_0_,
board0_.content as content2_0_0_,
board0_.title as title3_0_0_
from
board board0_
where
board0_.id=?
findAll을 쓰면 이렇게 불러 오게 된다.
https://github.com/MoonSeokHyun/SpringBoot_StudyBoard
GitHub - MoonSeokHyun/SpringBoot_StudyBoard
Contribute to MoonSeokHyun/SpringBoot_StudyBoard development by creating an account on GitHub.
github.com
반응형