Jin's Dev Story

[Thymeleaf] Thymeleaf 본문

Web & Android/Thymeleaf

[Thymeleaf] Thymeleaf

woojin._. 2023. 10. 17. 15:39

Thymeleaf

서버 사이드 템플릿 엔진의 한 종류

html 태그에 속성을 추가해 페이지에 동적으로 값을 추가하거나 처리할 수 있다.

서버 사이드 렌더링 하지 않고 브라우저에 띄워도 정상적인 화면을 볼 수 있다.

//상단에 적어주면 타임리프 사용 가능


// Gradle - build.gradle
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

Controller

@Controller
public class ThymeleafController {

		@GetMapping(value = "/thymeleaf/ex1")
		public String ex1(Model model) {

				model.addAttribute("data", "SpringBoot Study");

				return "thymeleaf/ex1";
		}
}

View

<!DOCTYPE html>
<html xmlns:th="http://wwww.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here></title>
</head>
<body>
		<h1>Hello World!!!</h1>
		<p th:text="{data}">스프링 부트 수업중!!</p>
</body>
</html>

 

 

application.properties

# Live Reload 기능 활성화
spring.devtools.livereload.enabled=true
# Thymeleaf cache 사용 중지
spring.thymeleaf.cache=false
## 추가사항
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.devtools.remote.restart.enabled=true

'Web & Android > Thymeleaf' 카테고리의 다른 글

[Thymeleaf] 날짜 변환  (0) 2023.10.17
[Thymeleaf] 기본 문법  (1) 2023.10.17
[Thymeleaf] 페이지 레이아웃  (1) 2023.10.17