【问题标题】:Spring-boot thymeleaf load HTML file from classpathSpring-boot thymeleaf 从类路径加载 HTML 文件
【发布时间】:2015-06-11 07:56:03
【问题描述】:

我有一个多模块项目结构,例如:

- application (parent module)
--- boot (web-app)
----- src/main/resources/templates/layout.html

---- todo (jar file)
----- src/main/resources/templates/home.html

在我的控制器上:

@RequestMapping(value = "/home")
public String home() {
    return "todo/home";
}

我收到如下错误消息:

Error resolving template "todo/home", template might not exist or
might not be accessible by any of the configured Template 
Resolvers]

是否需要专门为 spring 配置一些东西以在类路径上搜索模板?

【问题讨论】:

  • 你可以发布你的更新作为这个问题的答案并接受它

标签: java spring spring-boot


【解决方案1】:

添加以下属性解决了我的问题:

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

【讨论】:

    猜你喜欢
    • 2018-12-19
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2019-03-04
    • 2023-04-09
    • 2016-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多