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

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
    关注

    同问,后来是如何解决的

     

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站