首页 文章

我的Spring Boot应用程序无法看到Thymeleaf模板

提问于
浏览
0

我有一个Spring Boot应用程序,我用这些行在pom.xml中定义了我的百万美元依赖项:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

因此,当我启动应用程序并打印预定义的bean名称时,我会看到这些bean(我认为这对于thymeleaf正常运行很重要):

  • templateEngine

  • thymeleafResourceResolver

  • thymeleafViewResolver

项目结构如下所示:

enter image description here

我在fragments.html中定义了一些片段:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

  <body>

    <div class="container" th:fragment="copy">
        <hr>
        <footer>
            <div class="row">
                <div class="col-lg-12">
                    <p>Copyright &copy; Teamtool 2015</p>
                </div>
            </div>
        </footer>
    </div>

  </body>

</html>

..而我正在尝试使用我的index.html中的那些:

<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello AngularJS</title>
<base href="/" />
<link href="css/angular-bootstrap.css" rel="stylesheet">
<style type="text/css">
[ng\:cloak], [ng-cloak], .ng-cloak {
    display: none !important;
}
</style>
</head>

<body ng-app="hello" ng-cloak class="ng-cloak">
    <div ng-controller="navigation" class="container">
        <ul class="nav nav-pills" role="tablist">
            <li ng-class="{active:tab('home')}"><a href="/">home</a></li>
            ...
        </ul>
    </div>
    <div ng-view class="container"></div>

    <div class="col-md-3" th:include="fragments :: copy"></div>

    <script src="js/angular-bootstrap.js" type="text/javascript"></script>
    ...
</body>
</html>

但是我的模板没有添加到index.html中 . 我做错了什么?

2 回答

  • 0

    应用程序扫描 templates 文件夹中的Thymeleaf模板,将index.html移动到应该有效的 templates .

  • 0

    我尝试在这里是通用的,Spring引导将静态文件夹视为公共资源文件夹,用于从中提供 static 文件 . 正如你所说的 spring 启动也配置模板系统 - 在你的情况下百里香叶 - 它将开始查看模板文件夹 . Thymeleaf模板不是静态的,而是一种页面构建机制 .

    现在因为你配置了thymeleaf Springboot期望你想要渲染动态百万美元模板并在模板文件夹中寻找起点 . 它没有找到index.html文件显示Whitelabel页面 . 将index.html移动到模板文件夹时,它具有默认的起始点 . 您可以通过在您的某个控制器中映射诸如@RequestMapping(value =“/”)之类的URL路径,将任何其他文件名映射为应用程序的指示点 .

    您可以使用静态文件夹来提供角度JS文件,但模板必须位于模板文件夹中,除非您覆盖它 .

相关问题