[SpringBoot] 스프링부트에 Thymeleaf 환경 설정 방법 | 타임리프 | 템플릿 엔진 :: 매운코딩
728x90
300x250

스프링 부트는 템플릿 엔진을 이용한 view 화면 처리를 지원한다.

템플릿 엔진을 이용하면 사용자에게 제공되는 화면과 데이터를 분리하여 관리할 수 있다.

 

- 템플릿 엔진이란 ? cceeun.tistory.com/163

 

[Web]서버 템플릿 엔진과 클라이언트 템플릿 엔진이란?

보여지는 웹 화면영역을 개발할 때 많이 사용하는 템플릿 엔진에 대하여 알아보겠다. * 템플릿 엔진이란 ? 지정된 템플릿 양식과 데이터를 합쳐서 HTML 문서를 출력한다. 템플릿 엔진에는 서버사

cceeun.tistory.com

 

 

스프링 부트가 지원하는 템플릿 엔진은 여러개가 있으나 나는 Thymeleaf를 써보려고 한다.

 

타임리프가 인지하는 템플릿 파일의 기본 위치는 src/main/resources/templates 디렉토리이다.

해당 경로에 .html 파일을 작성한다.

 

1. 타임리프 의존성 추가하기

pom.xml 파일에 추가

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

 

2. application.propertise에 관련 설정 추가

# 정적 리소스에 변화가 있을 때 바로 반영한다. 
spring.devtools.livereload.enabled=true 

# thymeleaf 참조 경로 
spring.thymeleaf.prefix=classpath:/templates/ 
spring.thymeleaf.suffix=.html 

# thymeleaf 캐시 설정 - true면 변경시마다 매번 프로젝트를 다시 시작해야 반영된걸 볼 수 있음
spring.thymeleaf.cache=false 

# templates 디렉토리에 파일이 있는지 없는지 체크, 없으면 에러를 발생시킨다. 
spring.thymeleaf.check-template-location=true

 

 

 

 

참고자료 - https://dev-overload.tistory.com/25

 

[Spring] Spring Boot 시작하기 (2) - Thymeleaf 뷰 템플릿 사용

포스팅 시리즈 2020/09/28 - [Dev/Spring] - [Spring] Spring Boot 시작하기 (1) - 프로젝트 생성 2020/09/29 - [Dev/Spring] - [Spring] Spring Boot 시작하기 (2) - Thymeleaf 뷰 템플릿 사용 2020/09/30 - [De..

dev-overload.tistory.com

 

728x90

+ Recent posts