Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- JavaScript
- vscode
- lsof
- GIT
- 줄바꿈 문자
- IntelliJ
- Eclipse
- Windows
- tomcat
- ssh
- maVen
- port
- grep
- resource
- 네트워크
- profile
- netsh
- xargs
- import
- context
- Mac
- 단축키
- Source
- plugin
- web.xml
- find
- VirtualBox
- Quartz
- Windows 10
- bash
Archives
- Today
- Total
develog
[thymeleaf] Layout Dialect 본문
의존성을 추가한다
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
레이아웃 파일을 만든다 (layout1.html)
<!-- src/main/resources/templates/layout/layout1.html -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8">
<title>layout1</title>
</head>
<body>
<!-- layout1 -->
<!-- page1 content 를 출력한다 -->
<th:block layout:fragment="content"></th:block>
<!-- //page1 content 를 출력한다 -->
</body>
</html>
개별 페이지 파일 (page1.html)
layout 네임스페이스를 추가하고
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
>
layout1.html 파일을 사용하도록 지정한다
<html
layout:decorate="~{layout/layout1}"
>
전체 소스
<!-- src/main/resources/templates/page1.html -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout1}">
<head>
<meta charset="UTF-8">
<title>page1</title>
</head>
<body>
<h2>page1</h2>
<!-- page1 에서 사용할 content 를 정의한다 -->
<div layout:fragment="content">
<p>private content</p>
</div>
</body>
</html>
컨트롤러에서 개별 페이지를 호출한다
@GetMapping("/page1")
public String page1() {
return "page1";
}
https://github.com/ultraq/thymeleaf-layout-dialect
GitHub - ultraq/thymeleaf-layout-dialect: A dialect for Thymeleaf that lets you build layouts and reusable templates in order to
A dialect for Thymeleaf that lets you build layouts and reusable templates in order to improve code reuse - GitHub - ultraq/thymeleaf-layout-dialect: A dialect for Thymeleaf that lets you build lay...
github.com
Comments