728x90
λ°μν
1. ν경ꡬμΆ
* νμ리νμ νμ리ν λ μ΄μμμ λν μλ‘μ΄ μμ‘΄μ±μ μΆκ°νλ κ²
1-1. maven μμ‘΄μ± μΆκ°
https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect
<!-- thymeleaf-layout-dialect -->
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>3.1.0</version>
</dependency>
1-2. gradle μμ‘΄μ± μΆκ°
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
}
2. application.properties, application.yml νμΌ μ€μ νκΈ°
# Properties νμΌ - Thymeleaf μ€μ
spring.thymeleaf.enabled=true
spring.thymeleaf.cache=false
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
# yaml/yml νμΌ - Thymeleaf μ€μ
thymeleaf:
cache: false
check-template-location: true
prefix: classpath:/templates/
suffix: .html
enabled: true
3. ν΄λꡬ쑰
src
|-- main
| `-- resources
| `-- templates
| |-- common
| | |-- fragments
| | | |-- config.html
| | | |-- footer.html
| | | `-- header.html
| | `-- layout
| | `-- defaultLayout.html
| `-- other_templates.html
<!DOCTYPE html>
<!--λΌμ΄λΈλ¬λ¦¬ μ°Έμ‘° : Thymeleaf & Thymeleaf Layout -->
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<!--κ³΅ν΅ JS / CSS μμμ κ΄λ¦¬νλ νκ²½ μμ-->
<head th:replace="common/fragments/config :: config">
<title layout:title-pattern="$LAYOUT_TITLE : $CONTENT_TITLE">κ³΅ν΅ νμ΄ν</title>
</head>
<body>
<!--Header μμμ μ°Έμ‘°ν©λλ€.-->
<header th:replace="common/fragments/header :: header"></header>
<!--Content λ΄μ© μμμ μ°Έμ‘°ν©λλ€-->
<th:block layout:fragment="content"></th:block>
<!--Footer μμμ μ°Έμ‘°ν©λλ€.-->
<footer th:replace="common/fragments/footer :: footer"></footer>
</body>
</html>
header.html
<!DOCTYPE html>
<!-- Thymeleaf μ μΈ / headerFragment μμ μ μΈ-->
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:fragment="header">
<header id="header" class="header-logo-area">
</header>
</html>
footer.html
<!DOCTYPE html>
<!-- Thymeleaf μ μΈ / FooterFragment μμ μ μΈ-->
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:fragment="footer" >
<footer id="footer"></footer>
</html>
config.html
<!DOCTYPE html>
<!--Thymeleaf, ConfigFragment μ μΈ-->
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
th:fragment="config">
<head>
<!--Common Head-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1, user-scalable=yes,initial-scale=1.0"/>
<title>test</title>
<!--Common CSS -->
<link rel="stylesheet" th:href="@{https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css}" />
<link th:href="@{https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@200;400;700;900&display=swap}" rel="stylesheet" />
<link rel="stylesheet" th:href="@{/css/reset.css}" />
<link rel="stylesheet" th:href="@{/css/common.css}" />
<link rel="stylesheet" th:href="@{/css/style.css}" />
</head>
</html>
layout.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{common/layout/defaultLayout}">
<head>
<th:block layout:fragment="title">
<title>test</title>
</th:block>
</head>
<body>
<th:block layout:fragment="content">
νμ΄νμ΄
</th:block>
<th:block layout:fragment="script">
<script th:inline="javascript">
// μ€ν¬λ¦½νΈ λ΄μ©
</script>
</th:block>
</body>
</html>
λ°μν
'TIL > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Spring Security νμΌ μ€μ νκΈ° (0) | 2024.10.04 |
---|---|
JWT ν ν° κΈ°λ° κ°λ μμ보기 (0) | 2024.08.12 |
jre jdk μ°¨μ΄ (0) | 2024.01.18 |
java lombok annotation μμ보μ (0) | 2024.01.14 |
java μ€λ²λ‘λ©κ³Ό μ€λ²λΌμ΄λ© (0) | 2024.01.13 |