
Thymeleaf
서버 사이드 Java 템플릿 엔진.
HTML, XML, JavaScript, CSS 등과 같은 웹 페이지를 생성하는 데 사용
자바 코드와 함께 사용되는 것이 아니라 HTML과 같은 템플릿 파일에 태그를 추가하여 사용
-include-head.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>title</title>
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
</head>
</html>
-include-script.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<th:block th:fragment="script">
<!-- Bootstrap core JS-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS-->
<script src="js/scripts.js"></script>
</th:block>
</html>
-header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body>
<header th:fragment="레이아웃명(변수명1, 변수명2)">
<h1 th:text="${변수명1}"></h1>
<p th:text="${변수명2}"></p>
</header>
</body>
</html>
-index.html
<body>
<!-- Header-->
<header th:replace="layout/header::header(h1='두번째 페이지', p='') ">
</header>
...
-footer.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<footer class="bg-light py-5 mt-auto" th:fragment="footer" >
<div class="small text-center text-muted">Copyright © Website 2023</div>
</footer>
</html>
-index.html
<footer th:replace="layout/footer::footer"></footer>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!-- head -->
<head th:block th:include="common/include-head::head"></head>
<body>
<!-- header -->
<header th:replace="layout/header::header(h1='두번째 페이지', p='') "></header>
<!-- section -->
...
<!-- Footer -->
<footer th:replace="layout/footer::footer"></footer>
<!-- script -->
<th:block th:insert="common/include-script::script"></th:block>
</body>
</html>
사실 3개 크게 차이가 없긴 함