수월한 IT

thymeleaf 개요및 설정 본문

BOOKS/수월한 thymeleaf

thymeleaf 개요및 설정

IT여행자 2023. 7. 3. 23:09
728x90

thymeleaf는 view template 엔진으로 서버에서 클라이언트에게 응답할 브라우저 화면을 만들어 주는 역할을 한다.  thymeleaf는 Natural Template을 기반으로 기존 html 코드와 그 구조를 변경하지 않고 덧붙여 사용하는 방식이라 볼 수 있다.

 

특징

html 문서 내부에서 사용할 수 있으며 spring boot와 통합하는 작업이 매우 간단함.

관련 사이트 : https://www.thymeleaf.org/index.html

 

Thymeleaf

Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati

www.thymeleaf.org

 

VSCode에서 설정하기

1/3 extensions에서 thymeleaf와 thymeleaf-snipper 설치
2/3 pom.xml에서 thymeleaf dependency 추가
3/3 application.properties에 환경설정 추가하기

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

 

eclipse에서 설정하기

1/2 pom.xml에서 thymeleaf dependency 추가

2/2 application.properties에 환경 설정 추가(위와 동일)

 

eclipse Marketplace에서 thymeleaf를 검색하여 라이브러리를 설치해도 상관없지만 설치하지 않아도 무난히 사용할 수 있음.

 

html 파일에서 xmlns 설정

공식 문서에 따르면 일반적으로 html만으로 이루어진 파일에서는 굳이 xmlns를 설정할 필요는 없다. 하지만 html문서가 복합적인 언어로 이루어져 있다면 xmlns를 설정해 놓는 것이 안전하다 볼 수 있다.

 

<html lang=’ko’ xmlns:th=’http://www.thymeleaf.org’>