web-dev-qa-db-ja.com

春のブーツからThymeleafテンプレートを見つける方法

http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html でこのチュートリアルに従い、Thymeleafテンプレートに応答を送信する方法を学習しようとしています。しかし、私はこのエラーを受け取ります:テンプレートの場所が見つかりません:classpath:/ templates /(いくつかのテンプレートを追加するか、Thymeleaf構成を確認してください)

Message.htmlファイルをOther Sourcesディレクトリのsrc/main/resourcesの<default package>の下に配置しました。

したがって、構造は次のようになります。

SomeProject-その他のソース--src/main/resources ---<default package> ---- message.html

なぜ<default package>の下に表示されますが、<template>の下には表示されないのでしょうか。それは問題でしょうか?もしそうなら、私はそれをどのように変更するべきですか?私はnetbeansとmavenを使用しています。何かアイデアはありますか?これらは私のpom.xmlにある依存関係です:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>            
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

私が持っているコントローラーで

@RequestMapping(value = "message", method = RequestMethod.GET)
    public String messages(Model model) {
    model.addAttribute("messages", messageRepository.findAll());
    return "message";
}

そしてビューでは:

<ul th:each="message : ${messages}">
    <li th:text="${message.id}">1</li>
    <li><a href="#" th:text="${message.title}">Title ...</a></li>
    <li th:text="${message.text}">Text ...</li>
</ul>   
4
Gustav

ここで2つのこと:1. Mavenを使用している場合、私はフォルダー名のカスタマイズを想定していません。次に、フォルダ名はソースではなくsrcにする必要があります。 2.フォルダーの名前が変更されたら、テンプレートをsrc/resources内の 'templates'フォルダーに移動します。これは正常に動作するはずです。

0

Spring Bootはthymeleafテンプレートエンジンの自動構成サポートを含み、テンプレートはsrc/main/resources/templatesから自動的に選択されます。

テンプレートの場所をカスタマイズする場合は、Spring Bootで使用可能な以下のthymeleafプロパティ構成を使用します。

  • spring.thymeleaf.check-template = true#レンダリングする前にテンプレートが存在することを確認します。

  • spring.thymeleaf.check-template-location = true#テンプレートの場所が存在することを確認します。

  • spring.thymeleaf.enabled = true#MVC Thymeleafビューの解像度を有効にします。

  • spring.thymeleaf.prefix = classpath:/ templates /#URLの構築時に名前を表示するために付加されるプレフィックス。

  • spring.thymeleaf.suffix = .html#URLの構築時にビュー名に追加されるサフィックス。

7
Chandu

Thymeleafテンプレートファイルの場合は、フォルダーsrc/main/resources/templates /に配置し、チェックアウトも機能します http://www.mkyong.com/spring-boot/spring-boot-hello-world -example-thymeleaf / 。春ブーツで胸腺をキックスタートするのが簡単であることを願っています。

1
Yogendra Mishra

Thymeleafテンプレートのデフォルトのディレクトリの場所は次のとおりです。

src/main/resources/templates

その他のパスは、Spring Bootの標準的な規則です。

Spring Boot thymeleaf directory structure

1
chocksaway