thymeleaf layout 적용 시키기 (수정)

김예지·2023년 3월 29일
0

예전 프로젝트는 jsp파일에 include 를 하여 레이아웃을 적용시켰지만 스프링부트 + thymeleaf 을 사용하면 tomcat을 별도로 설치 할 필요도 없고 jar로 빌드 시킬 수 있기때문에 이번 프로젝트는 jsp파일이 아닌 thymeleaf 를 사용하기위해 수정하였다

  1. layout 라이브러리 추가해주기
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
  1. application.properties 파일에 추가해주기
spring.thymeleaf.enabled=true
spring.thymeleaf.cache=false
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
  1. main.html 파일에 소스추가
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
  1. layout.html 파일에 이름 추가해주기
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      th:fragment="SideContent">
  1. main.html 파일에 layout 페이지 추가해주기
<th:block th:replace="/layout/sideContent :: SideContent"></th:block> //기존 
<th:block th:replace="/layout/sideContent :: SideContent"></th:block> //수정

인텔리제이에서 실행 할 때는 정상적으로 실행이 됐지만 터미널을 통해 빌드했을 때 오류가 나왔다 검색해보니 경로의 문제여서 경로를 수정하니 제대로 실행이 되었다 휴!ㅜ
참고 : https://adjh54.tistory.com/75

profile
나만의 방식을 찾아가는 신입신입 개발자

0개의 댓글