Day100 실습프로젝트(Thymeleaf)
Thymeleaf
1. Thymleaf 적용하기
- spring boot에서 thymeleaf를 적용하기 위해서는 설정파일의 변경이 필요하다
- prefix : ViewResolver가 찾을 파일의 경로를 설정한다.
- suffix :
.html
이 기본 default이다.1 2
spring.thymeleaf.prefix=file:src/main/resources/templates/ #spring.thymeleaf.suffix=.html 디폴트 값이다.
2. header.html수정
- 헤더 값은 모든 템플릿에서 공통으로 참조하는 값이므로 조각을 만들어서 적용한다.
head정보에 fragment조건을 설정한다.
1 2 3 4 5 6 7 8 9 10 11
<head data-th-fragment="head"> <meta charset='UTF-8'> <title>Title</title> <link href='/css/common.css' rel='stylesheet'> </head> <!--조각을 적용하는 html에서는 replace로 받는다. --> <head data-th-replace="~{header :: head}"> </head> <!-- ~ : 템플릿 경로의 루트 --> <!-- header : header.html의 파일명--> <!-- head : fragment에 할당한 조각명-->
3. Project.view 수정
이미 체크된 데이터는 data-th-checked를 통해 체크여부를 판단한다.
1 2 3 4 5 6 7 8
<ul data-th-if="${users.size() > 0}"> <li data-th-each="user : ${users}"> <input data-th-checked="${project.members.contains(user)}" data-th-text="${user.name}" data-th-value="${user.no}" name='memberNos' type='checkbox'>홍길동</li> </ul>
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.