zoukankan      html  css  js  c++  java
  • 【SpringBoot+Mybatis+thymeleaf报错】Error resolving template "XXX", template might not exist or might not be accessible by any of the configured

    解决方法一:

    原因:在使用springboot的过程中,如果使用thymeleaf作为模板文件,则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错。

    在application.yml中添加以下配置

    spring:
      thymeleaf:
        prefix: classpath:/templates/
        mode: HTML
        cache: false
        encoding: UTF-8
        #     新版本不支持content-type: text/html,故新写法
        servlet:
          content-type: text/html
    

    再在pom.xml 添加以下依赖

    <dependency>
    	<groupId>net.sourceforge.nekohtml</groupId>
    	<artifactId>nekohtml</artifactId>
    	<version>1.9.22</version>
    </dependency>
    

    解决方法二:

    原因:Spring Boot没有解析出静态资源文件位置

    <build>
            <!-- 配置将哪些资源文件(静态文件/模板文件/mapper文件)加载到tomcat输出目录里 -->
            <resources>
                <resource>
                    <directory>src/main/java</directory><!--java文件的路径-->
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                    <!-- <filtering>false</filtering>-->
                </resource>
                <resource>
                    <directory>src/main/resources</directory><!--资源文件的路径-->
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                    <!-- <filtering>false</filtering>-->
                </resource>
            </resources>
    
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

      

    解决方法三:

    原因:这个是我自己的锅,我原先使用的是freemaker引擎,文件格式为.ftl,故切换thymeleaf引擎后没有改为.html,修改文件后缀即可。

    解决方法四:

    原因:可能是由于找不到前端VIew路径的原因。

    具体参考我的后台(注意ModelAndView的值):

    @GetMapping("/listUser")
        public ModelAndView listUser(){
            ModelAndView model = new ModelAndView("user/list");
            model.addObject("userList",userservice.listUser());
            return model;
        }

    项目结构:

    实在找不到,application.yml中加入:

    spring:
      thymeleaf:
        prefix: classpath:/templates/
  • 相关阅读:
    django 修改默认的user表和默认的认证系统
    django 'WSGIRequest' object has no attribute 'user'
    python scrapy简单爬虫记录(实现简单爬取知乎)
    python 文件操作的注意事项
    windows cmd命令
    数据库便捷的软件
    BCB Access violateion at Address 0000 0003. Read of address 0000 0003
    C++Builder6.0 新建和打开项目软件死机
    163邮箱账号
    使用 MtVerify.h头文件 ,用的时候把他头文件的内容添加到项目
  • 原文地址:https://www.cnblogs.com/gdvxfgv/p/10792282.html
Copyright © 2011-2022 走看看