thymeleaf_layout
ํ
ํ๋ฆฟ ๋ ์ด์์ 1
ํ ํ๋ฆฟ์์ ์ผ๋ถ ์ฝ๋ ์กฐ๊ฐ์ ๊ฐ์ง๊ณ ์์ ์ฌ์ฉํ๋ค๋ฉด ์ฝ๋ ์กฐ๊ฐ์ ๋ ์ด์์์ ๋๊ฒจ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๋ ์๋ค. ์๋ฅผ ๋ค๋ฉด
<head>์ ๊ณตํต์ผ๋ก ์ฌ์ฉํ๋css,javascript๊ฐ์ ๊ณตํต ์ ๋ณด๋ค์ ํ ๊ณณ์ ๋ชจ์๋๊ณ ๊ณตํต์ผ๋ก ์ฌ์ฉํ์ง๋ง ๊ฐ ํ์ด์ง๋ง๋ค ํ์ํ ์ ๋ณด๋ฅผ ๋ ์ถ๊ฐํด์ ์ฌ์ฉํ ์ ์๋ค.
์ปจํธ๋กค๋ฌ
@GetMapping("/layout")
public String layout() {
return "template/layout/layoutMain";
}layout_base.html
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="common_header(title,links)">
<title th:replace="${title}">๋ ์ด์์ ํ์ดํ</title>
<!-- ๊ณตํต -->
<link rel="stylesheet" type="text/css" media="all" th:href="@{/css/ awesomeapp.css}">
<link rel="shortcut icon" th:href="@{/images/favicon.ico}">
<script type="text/javascript" th:src="@{/sh/scripts/codebase.js}"></script>
<!-- ์ถ๊ฐ -->
<th:block th:replace="${links}" />
</head>layoutMain.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="template/layout/base :: common_header(~{::title},~{::link})">
<title>๋ฉ์ธ ํ์ดํ</title>
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
<link rel="stylesheet" th:href="@{/themes/smoothness/jquery-ui.css}">
</head>
<body>
๋ฉ์ธ ์ปจํ
์ธ
</body>
</html>๋ ๋๋ง ๋ HTML
<!DOCTYPE html>
<html>
<head>
<title>๋ฉ์ธ ํ์ดํ</title>
<!-- ๊ณตํต -->
<link rel="stylesheet" type="text/css" media="all" href="/css/ awesomeapp.css">
<link rel="shortcut icon" href="/images/favicon.ico">
<script type="text/javascript" src="/sh/scripts/codebase.js"></script>
<!-- ์ถ๊ฐ -->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/themes/smoothness/jquery-ui.css">
</head>
<body>
๋ฉ์ธ ์ปจํ
์ธ
</body>
</html>common_header(~{::title},~{::link})ํ์ฌ ํ์ด์ง์ title ํ๊ทธ์ link ํ๊ทธ๋ค์ ์ ๋ฌํ๋ค.
ํ
ํ๋ฆฟ ๋ ์ด์์ 2
<head>๋ฟ๋ง ์๋๋ผ HTML ์ ์ฒด์ ์ ์ฉํ ์ ์๋ค.
์ปจํธ๋กค๋ฌ
@GetMapping("/layoutExtend")
public String layoutExtend() {
return "template/layoutExtend/layoutExtendMain";
}layoutFile.html
<!DOCTYPE html>
<html th:fragment="layout (title, content)" xmlns:th="http://www.thymeleaf.org">
<head>
<title th:replace="${title}">๋ ์ด์์ ํ์ดํ</title>
</head>
<body>
<h1>๋ ์ด์์ H1</h1>
<div th:replace="${content}">
<p>๋ ์ด์์ ์ปจํ
์ธ </p>
</div>
<footer>
๋ ์ด์์ ํธํฐ
</footer>
</body>
</html>layoutExtendMain.html
<!DOCTYPE html>
<html th:replace="~{template/layoutExtend/layoutFile :: layout(~{::title}, ~{::section})}"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>๋ฉ์ธ ํ์ด์ง ํ์ดํ</title>
</head>
<body>
<section>
<p>๋ฉ์ธ ํ์ด์ง ์ปจํ
์ธ </p>
<div>๋ฉ์ธ ํ์ด์ง ํฌํจ ๋ด์ฉ</div>
</section>
</body>
</html>๋ ๋๋ง ๋ HTML
<!DOCTYPE html>
<html>
<head>
<title>๋ฉ์ธ ํ์ด์ง ํ์ดํ</title>
</head>
<body>
<h1>๋ ์ด์์ H1</h1>
<section>
<p>๋ฉ์ธ ํ์ด์ง ์ปจํ
์ธ </p>
<div>๋ฉ์ธ ํ์ด์ง ํฌํจ ๋ด์ฉ</div>
</section>
<footer>
๋ ์ด์์ ํธํฐ
</footer>
</body>
</html>Last updated