この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:3
ページ更新者:guest
更新日時:2026-05-17 14:48:25

タイトル: 導入方法と基本動作

本稿はThymeleafの導入方法と基本動作について説明します。

 

Mavenへの記述

pom.xmlに以下の記述をしてインストールします。

org.springframework.boot

spring-boot-starter-thymeleaf

 

テンプレートファイルの設置

以下のディレクトリにテンプレートファイルを作成します。

/src/main/resources/templates/test/index.html

 

index.htmlの内容は以下の通りです。

xmlns:th="http://www.thymeleaf.org">

Thymeleaf Page

Thymeleaf Page

th:text="${message}">

 

コントローラーの作成

以下を参考にコントローラーを作成します。

@Controller

public class TestController {

 

@RequestMapping("/")

public String index(Model model) {

String message = "Hello!?";

model.addAttribute("message", message);

return "/test/index";

}

}

 

出力結果