Spring-boot百万美元从classpath加载HTML文件 [英] Spring-boot thymeleaf load HTML file from classpath
本文介绍了Spring-boot百万美元从classpath加载HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多模块项目结构,如:
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
并在我的控制器上:
@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的类,以便在类路径上搜索模板?
Is there configuration needed to configure something specially for spring for searching templates on class path?
更新
已解决。添加以下属性解决了我的问题:
Solved. 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
推荐答案
添加以下属性解决了我的问题:
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
这篇关于Spring-boot百万美元从classpath加载HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文