没有找到 html 模板,Spring Boot and Thymeleaf:找不到HTML模板

我正在嘗試用Thymeleaf創建一個基於Spring Boot的應用程序。我使用PetClinic樣本作爲起點。 我的應用程序找不到一些模板。Spring Boot and Thymeleaf:找不到HTML模板

我的項目是建立在標準的方式:

/src

/main

/java

/com.example

MyWebApplication.java

HomeController.java

/resources

/static

/css

/templates

/fragments

layout.html

home.html

application.properties

的pom.xml

org.springframework.boot

spring-boot-starter-parent

1.5.1.RELEASE

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-thymeleaf

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-devtools

true

MyWebApplication.java

@SpringBootApplication

public class MyWebApplication {

public static void main(String[] args) {

SpringApplication.run(MyWebApplication.class, args);

}

}

HomeController.java

home.html做爲

xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"

th:replace="~{fragments/layout :: layout (~{::body},'home')}">

Welcome

的layout.html

th:fragment="layout (template, menu)">

Web Interface

application.properties是空的。

當我瀏覽到http://localhost:8080我得到的錯誤:

Error resolving template "~{fragments/layout", template might not exist or might not be accessible by any of the configured Template Resolvers (home:5)

如果我刪除了「日:更換」從home.html的屬性,它會顯示歡迎信息。

瀏覽類似問題(例如this one),我看到其他人創建了ThymeleafViewResolver bean。

問題:

爲什麼不能找到我的模板?

我是否需要創建模板解析器?如果是這樣,那麼寵物診所樣本怎麼沒有?它的模板解析器來自哪裏?

據我所見,它的設置方式與寵物診所樣品一樣,那麼有什麼區別?

2017-02-03

AlanW

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值