【问题标题】:Spring boot doesn't identify html templates without Thymeleaf dependencySpring boot 无法识别没有 Thymeleaf 依赖的 html 模板
【发布时间】:2021-08-16 23:16:44
【问题描述】:

我使用 spring-boot 2.5.0 和 maven 作为依赖管理工具。到目前为止,我的项目中有以下依赖项。

"<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>"

我想使用 jsp 代替 thymeleaf,但是当我将“index.html”文件放入 templatesresources 的子文件夹时em> 文件夹它无法识别 html 文件并引发白色标签错误。当我添加 thymeleaf 依赖项时,它可以完美运行并识别 html 文件。 那么,我应该怎么做才能让spring-boot在不添加thymeleaf依赖的情况下检测我的html文件。顺便说一句,我以前从未使用过jsp。

【问题讨论】:

  • 我不确定你在用 html 文件和 JSP 做什么——你必须提供你想要实现的具体细节。
  • 看到这个link 可能有用
  • @BoristheSpider 我正在练习,只是在浏览器中创建一个视图。在练习时,我使用的是一个简单的 html 文件,它只是说你好。我计划稍后使用 jsp 文件对其进行更改,但这不是问题。问题是我的文件没有被检测到。它是 jsp 还是 html 文件是否重要?我只是要求检测我的视图。
  • 只是一个旁注:如果你刚开始,你肯定应该选择百里香。比jsp干净多了。
  • 谢谢@gowridev,非常有帮助

标签: java spring spring-boot thymeleaf


【解决方案1】:

您似乎缺少这两件事中的任何一件。

  1. 您应该在属性/yaml 文件中将所需值放在属性下方

    spring.mvc.view.prefix:
    spring.mvc.view.suffix: <.extension>

  2. 检查您的控制器是否发送了正确的视图名称。

【讨论】:

猜你喜欢
  • 2019-02-26
  • 2022-01-01
  • 2021-05-30
  • 2022-11-14
  • 2016-01-26
  • 2017-06-21
  • 2018-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多