포트폴리오/SPRINGBOOT 옛날

2-07 : template

서버관리자 페페 2022. 9. 30. 21:46

단 하나의 맥락

- thymeleaf P/I 로 자바 데이터를 조회하여, 상세페이지 template을 웹사이트에 띄우기

 

-

 

Semiflow Bundle

- question/list URL을 QuestionController에 매핑

- 타임리프 템플릿 엔진 설치

- question_list.html을 QuestionController에 매핑

- 데이터 템플릿에 전달

- 전달받은 데이터 웹에 사용

 

-

 

자각

- implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

- implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' 사용

 

- @RequiredArgsConstructor로 D/I 한다

- 리포지토리의 접근제어자는 private final이다

- 매핑된 메소드의 signal로 Model model을 사용한다

- Model은 "import org.springframework.ui.Model;" 로 P/I 를 넣는다

- List<Question> questionList = this.questionRepository.findAll();

- model.Addattribute("questionList", questionList);

- return "question_list"; // 전달

 

- <table></table> 로 표 형식을 사용한다

- 상단 <thead></thead>와, 하단 <tbody></tbody> 로 구성 되어있다

- 각 테이블단에는 <tr></tr> 이 하나의 열(row)으로 구현된다

- 열은 <th></th>인 타임리프 단위로 구성되며, 이것은 비로소 하나의 항목을 나타낸다

- head 단에는 단순히 "<th>제목</th>", "<th>작성일시</th>" 정도의 고정된 문자로 표현하지만

- body 단에는 각 Question별로 row가 생성되므로 <tr th:each="question : ${questionList}"></tr>로 Question 갯수만큼 열을 구현

- <td th:text="${question.subject"}></td>

- <td th:text="${question.createDate}"></td> 를 항목으로 넣어준다

  

 

'포트폴리오 > SPRINGBOOT 옛날' 카테고리의 다른 글

2-09 : Service  (4) 2022.10.01
2-08 : redirecting to ROOT URL  (1) 2022.10.01
2-05 : repository  (6) 2022.09.29
2-04 : Entity  (4) 2022.09.27
2-03 : ORM / JPA / H2-DB / JPA 셋팅  (4) 2022.09.27