카테고리 없음

[Spring] Thymeleaf를 사용하여 layout 나누기

quedevel 2020. 3. 13. 15:50
728x90
반응형

layout작업을 하기 위해 라이브러리 추가

		<!-- https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect -->
		<dependency>
			<groupId>nz.net.ultraq.thymeleaf</groupId>
			<artifactId>thymeleaf-layout-dialect</artifactId>
			<version>2.4.1</version>
		</dependency>

main_header.html

<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="main_header">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" th:href="@{~/css/lib/bootstrap.min.css}">
        <link rel="stylesheet" th:href="@{~/css/app/common.css}">
        <title>Document</title>
    </head>
</head>
</html>

main_footer.html

<html xmlns:th="http://www.thymeleaf.org">
<footer th:fragment="main_footer">
        <script th:src="@{~/js/lib/jquery-2.2.4.min.js}"></script>
        <script th:src="@{~/js/lib/bootstrap.min.js}"></script>
        <script th:src="@{~/js/app/common.js}"></script>
</footer>
</html>

index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<th:block th:include="layout/main_header" th:remove="tag"></th:block>
<body>
	<h1>Index Page</h1>
    <th:block th:include="layout/main_footer :: main_footer" th:remove="tag"></th:block>
</body>

</html>

 

728x90
반응형