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

    同问,后来是如何解决的

     

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料