본문 바로가기
Java/Spring Boot

[SpringBoot] Thymeleaf 적용 방법

by HoneyIT 2023. 8. 30.

1. application.properties 설정 추가

spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=false

 

2. build.gradle 설정 추가

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

 

build.gradle

 

3. html 경로 설정

templates > main > hello.html

- 설정된 templates 하위 경로에 html 파일 생성

 

MmainController

- Controller를 통해 해당 경로 html 호출

 

4. Tyhmeleaf가 적용되지 않는 경우

Refresh Gradle Project

- 혹시나 Thymeleaf가 적용되지 않는 경우 프로젝트 우클릭 > Gradle > Refresh Gradle Project 클릭 후 Spring Boot 재실행

 

5. html 호출 확인

hello.html

- templates 하위 경로의 html을 정상적으로 불러오는 것을 확인할 수 있습니다.