前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Error resolving template [], template might not exist or might not be accessible by any of the conf

Error resolving template [], template might not exist or might not be accessible by any of the conf

作者头像
圆号本昊
发布2021-09-24 11:09:22
4K0
发布2021-09-24 11:09:22
举报
文章被收录于专栏:github@hornhuang

一、问题:

  • Error resolving template [/index], template might not exist or might not be accessible by any of the configured Template Resolvers
  • 出现在 SpringBoot 项目使用 java -jar 运行时

二、解决

  • 分别检查下面三个地方

2.1 在 pom.xml 中添加 thymeleaf 依赖

  • 没有的话加下,有的话不用加
代码语言:javascript
复制
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-thymeleafartifactId>
dependency>

2.2 application.yml添加相应的thymeleaf 的配置

  • 我原先的配置不全,是错误的
  • 需要修改成下面这样
代码语言:javascript
复制
thymeleaf:
  prefix: classpath:/templates/  #prefix:指定模板所在的目录
  check-template-location: true  #check-tempate-location: 检查模板路径是否存在
  cache: false  #cache: 是否缓存,开发模式下设置为false,避免改了模板还要重启服务器,线上设置为true,可以提高性能。
  suffix:  .html
  #encoding: UTF-8
  #content-type: text/html
  mode: HTML5
  • 示例图(方便大家对应着看)

2.3 访问路径 @controller 的类

  • 记住,页面需要以 ModelAndView 对象的形式放回
代码语言:javascript
复制
    @RequestMapping("/")
    public ModelAndView indexHtml(HashMap<String, Object> map) {
        ModelAndView mv =  new ModelAndView("index");
        return mv;
    }
  • 对于 index 的路径我是这样的,大家可以对照下
  • 到这里从新跑一下就能解决啦~ cheers~

三、总结

  • 如果还有问题可以截图私聊我,我有时间的话可以帮大家看看
  • 如果本文对你有用,欢迎点赞活着关注支持,因为这是对我最大的鼓励 ????
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/04/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、问题:
  • 二、解决
    • 2.1 在 pom.xml 中添加 thymeleaf 依赖
      • 2.2 application.yml添加相应的thymeleaf 的配置
        • 2.3 访问路径 @controller 的类
        • 三、总结
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档