#author("2019-11-18T13:41:01+08:00","default:Admin","Admin") Thymeleaf

依赖包

检查依赖的包,可参考。或直接在pom.xml中添加

https://ultraq.github.io/thymeleaf-layout-dialect/Installation.html 
<dependency>
	<groupId>nz.net.ultraq.thymeleaf</groupId>
	<artifactId>thymeleaf-layout-dialect</artifactId>
	<version>2.3.0</version>
</dependency>

这是对layout dialect的依赖。

定义模板

首先定义模板default.html,放置位置在resources/templates中,模板放在其子目录layout中。

模板格式如下:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
	<title>Insert title here</title>
	
	<link href="/webjars/materializecss/1.0.0-rc.2/css/materialize.css" type="text/css" 
		rel="stylesheet" media="screen,projection" />
</head>
<body>
	<section layout:fragment="content">
		<p>Page content goes here</p>
	</section>
	
	<script src="/webjars/jquery/3.3.1-1/jquery.js"></script>
	<script src="/webjars/materializecss/1.0.0-rc.2/js/materialize.js"></script>
</body>
</html>

这里注意两个地方,一个是<html>标签中的xmlns:layout的设置,另一个是<section>中layout:fragment的设置,其值是其他页面引用此模板时指定的fragment值。

使用模板

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorate="~{layout/default}">
<head lang="en">
<title>Search</title>
</head>
<body>
	<div class="row" layout:fragment="content">
		<h4 class="indigo-text center">Please enter your name</h4>
		<form action="/result" method="get" class="col1 sl2">
			<div class="row center">
				<div class="input-field col s6 offset-s3">
					<i class="mdi-action-search prefix"></i>
					<input id="search" name="search" type="text" class="validate"/>
					<label for="search">Search</label>
				</div>
			</div>
		</form>
	</div>
</body>
</html>

需要注意的两个地方:

1. html标签中layout:decorate的设置。有两种写法,一种是

layout:decorate="layout/defalut"

另外一种是上面代码中写的

layout:decorate="~{layout/default}"

路径都是相对resources/templates目录的。

2. div标签中的layout:fragment值的设置。其值应设置成模板中section中的layout:fragment的值



あなたのお住まいの地域で最安のブロードバンド選び

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:42:50 (1627d)

yVoC[UNLIMITȂ1~] ECirŃ|C Yahoo yV LINEf[^[Ōz500~`I


z[y[W ̃NWbgJ[h COiq 萔O~ył񂫁z COsیI COze