Spring Boot2 で画面を共通化する方法のメモです。
下記サイトの方法で、Spring Boot 1.4では動作しました。
https://www.saka-en.com/java/spring-boot-thymeleaf-layout/
Spring Boot2で同じことを実施したところ、
index.htmlの"html"タグ内に記載した
"layout:decorate="~{layout/layout}""が
解釈されず、正しく動作しませんでした。
pom.xmlに下記の内容を追記すると正しく動きました。
--------------------------------------------------------
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
--------------------------------------------------------
"spring-boot-starter-thymeleaf"では、
"thymeleaf-layout-dialect"が含まれないようです。
試した環境のバージョンは下記の通りです。
・Spring Boot 2.1.4.RELEASE
・thymeleaf-3.0.11.RELEASE
・thymeleaf-layout-dialect-2.3.0
以下、参考になるサイトです。
・依存関係の確認方法
https://ts0818.hatenablog.com/entry/2017/09/14/223604
※依存関係の確認方法を参考にしました。
・Thymeleaf: Custom Layout Dialect
https://www.baeldung.com/thymeleaf-spring-layouts