template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决,
分享于 点击 14540 次 点评:244
template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决,
初学者在maven spring boot web项目中使用thymeleaf 模板,经常会遇到 “template might not exist or might not be accessible by any of the configured Template Resolvers”这个问题,让人很头疼。其实这个错误的描述很清楚:
第一、模板不存在 ,第二、模板无法被解析器解析
带着这两个问题来找答案:
首先确定在Maven的资源管理文件中 pom.xml确保引入 spring-boot-starter-thymeleaf这个jar包,如果配置中有,它会自动下载到本地库。
<!-- 引入 thymeleaf 模板依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
接下来在application.properties 中添加如下配置:
spring.thymeleaf.mode=HTML spring.thymeleaf.cache=true spring.thymeleaf.enabled=true spring.thymeleaf.encoding=utf-8 spring.thymeleaf.prefix=/resources/templates/ spring.thymeleaf.suffix=.html #文件后缀为.html或.jsp都可以,取决于/resources/templates/下对应的文件
有了以上这两步就没问题了,如下是项目的目录结构
Spring 启动类及MVC的 控制器部分代码:

浏览器访问:
相关文章
- 暂无相关文章
用户点评