thymeleaf는 thymeleaf템플릿 엔진을 사용하기 위한 기초 라이브러리이며, thymeleaf-layout-dialect는 thymeleaf템플릿 엔진 기반 레이아웃을 구성할때 필요한 라이브러리이다. 자애로운 spring-boot-starter-parent께서 위 둘의 버전관리를 자동으로 해주시니, version을 생략해도 된다. 본인의 경우 2.1.1 버전이 적용되었다.
html파일로 레이아웃 구성
springboot web 프로젝트에서 기본적으로 resources/templates에서 뷰를 찾는다. template/layout/default.html은 thymeleaf의 레이아웃이 되는 파일이다. template/fragments/config.html template/fragments/footer.html template/fragments/header.html 파일은 defaout.html 레이아웃의 내부를 구성하는 부품 화면이 된다. template/index.html은 핵심인 contents가 되는 페이지이다.
default.html
이 파일이 thymeleaf 레이아웃을 잡아주는 핵심파일이 된다. head th:replace는 head 영역의 부속 페이지를 말한다. 부속페이지는 fragments/config(html을 생략한다.) 그리고 그 파일의 configFragment 태그를 잘라와 사용한다는 의미이다. header footer도 비슷한 의미이다. layout이 되는 html의 태그는 xmlns:layout=”http://www.ultraq.net.nz/thymeleaf/layout"를 삽입해야 한다. layout:fragment=”content” 부분은 서버의 요청별로 달라지는 컨텐츠 페이지가 된다.(index.html)
head의 공통적인 부분을 담당하는 페이지이다. css, js 파일따위를 관리 할 수 있다. 특의한 점은 <th:block layout:fragment=”css”> <th:block layout:fragment=”script”> 인데, 레이아웃의 content가 되는 index.html에 작성된 css나, js를 가져와서 적용하는 부분이다.