java Spring-boot thymeleaf 从类路径加载 HTML 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29479403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:21:44 来源:igfitidea点击:
Spring-boot thymeleaf load HTML file from classpath
提问by aymeba
I've a multi module project structure like :
我有一个多模块项目结构,如:
- application (parent module)
--- boot (web-app)
----- src/main/resources/templates/layout.html
---- todo (jar file)
----- src/main/resources/templates/home.html
and on my controller:
在我的控制器上:
@RequestMapping(value = "/home")
public String home() {
return "todo/home";
}
I'm getting the error message as below:
我收到如下错误消息:
Error resolving template "todo/home", template might not exist or
might not be accessible by any of the configured Template
Resolvers]
Is there configuration needed to configure something specially for spring for searching templates on class path?
是否需要配置专门为 spring 在类路径上搜索模板的东西?
采纳答案by aymeba
Adding following properties solves my problem:
添加以下属性解决了我的问题:
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