layout.htmlにテンプレのデザインした画面を用意して、それぞれのページを表示していきたいのですが
layout.htmlを参照せずindex.htmlがそのまま出てきます。。。
OS:macOS Java version:8
コードは以下のようになっております。
index.html
html
1<!DOCTYPE html> 2<html lang="ja" 3 layout:decorate="~{layout/layout}" 4 xmlns="http://www.w3.org/1999/xhtml" 5 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 6 xmlns:th="http://www.thymeleaf.org"> 7<head layout:replace="~{layout/layout :: baseHead('TOP画面',~{::link})}"> 8 <link rel="stylesheet" th:href="@{/css/layout.css}" type="text/css"/> 9</head> 10<body> 11 <div layout:fragment="content"> 12 <div>aaa</div> 13 <div>bbb</div> 14 </div> 15</body> 16</html>
layout.html
html
1<!DOCTYPE html> 2<html lang="ja" 3 xmlns="http://www.w3.org/1999/xhtml" 4 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 5 xmlns:th="http://www.thymeleaf.org"> 6<head layout:fragment="baseHead(title,links)"> 7 <meta charset="UTF-8"> 8 <title layout:text="${title==null}? 'TODOリスト' : ${title} +' | TODOリスト'">TODOリスト</title> 9 10 <layout:block layout:replace="${links}" /> 11</head> 12<body> 13 <div layout:replace="~{layout/header::header}"></div> 14 <main class="container"> 15 <div layout:fragment="content" th:remove="tag"></div> 16 </main> 17</body> 18</html>
header.html
html
1<!DOCTYPE html> 2<html lang="ja" 3 xmlns="http://www.w3.org/1999/xhtml" 4 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> 5 <body> 6 <header layout:fragment="header"> 7 <a href="/">TODOリスト</a> 8 <a href="/search/">検索</a> 9 </header> 10 </body> 11</html>
階層については
templates
┣layout
┃ ┣header.html
┃ ┗layout.html
┗index.html
どうぞよろしくお願いいたします。
追記
gradle.buildについては以下に示します。
buildscript { ext { springBootVersion = '2.1.1.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.hashin' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0') implementation('org.springframework.boot:spring-boot-starter-thymeleaf') implementation('org.springframework.boot:spring-boot-starter-web') runtimeOnly('org.springframework.boot:spring-boot-devtools') runtimeOnly('mysql:mysql-connector-java') testImplementation('org.springframework.boot:spring-boot-starter-test') }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。