タイトル: 導入方法と基本動作
本稿はThymeleafの導入方法と基本動作について説明します。
Mavenへの記述
pom.xmlに以下の記述をしてインストールします。
|
|
テンプレートファイルの設置
以下のディレクトリにテンプレートファイルを作成します。
|
/src/main/resources/templates/test/index.html |
index.htmlの内容は以下の通りです。
|
xmlns:th="http://www.thymeleaf.org">
th:text="${message}">
|
コントローラーの作成
以下を参考にコントローラーを作成します。
|
@Controller public class TestController {
@RequestMapping("/") public String index(Model model) { String message = "Hello!?"; model.addAttribute("message", message); return "/test/index"; } } |
出力結果
