EvansAckles 2019-03-09 13:52 采纳率: 40%
浏览 7985
已结题

springboot引入thymeleaf后不但thymeleaf用不了,页面都打不开了,这是为什么?

这两天我跟着视频敲代码,一度能够正常页面跳转,后面可能在学新东西的时候做了修改,导致页面无法跳转,而且thymeleaf也无法正常对页面上正在写的th:text进行提醒(怀疑thymeleaf导入失败),无从下手

首先pom.xml引入了web、webjars、thymeleaf的依赖

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>

        <thymeleaf.version>3.0.7 RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
    </properties>

    <dependencies>
        <!--web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--webjars依赖-->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

 <!--引入thymeleaf-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

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

    </dependencies>

application.proprties中的配置

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

spring.messages.basename=i18n.index
spring.messages.cache-seconds=-1

MyConfig配置类,有点不太理解这个,还在消化中

@Configuration
public class MyConfig extends WebMvcConfigurerAdapter {

            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/index.html").setViewName("index");
            }
}

controller类如下

@Controller
public class HelloController {
    @RequestMapping("/index")
    public String indexPage(){
        return "index";
                }
}

包结构如下
图片说明

index.html页面上thymeleaf也没有反应
图片说明

启动后页面跳转出错
图片说明

经过调查发现是thymeleaf的jar包并没有导进去本地仓库,手动导入后可以进行正常页面跳转,但是

还是不能在前端页面显示thymeleaf语法提示,xmlns:th="http://www.thymeleaf.org"我是加了的啊
同时file--》settings--》plugins里找不到关于thymeleaf的插件,求助!

  • 写回答

2条回答 默认 最新

  • khazix__ 2021-01-25 11:05
    关注

    同问,后来是如何解决的

     

    评论

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面