SpringBoot + Thymeleaf模板引擎

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fantasic_van/article/details/79691102

1、SpringBoot支持的常用的模板引擎有:

  • Thymeleaf
  • Freemarker

这里主要记录一下踩坑记录

2、创建一个springboot项目,并添加Thymeleaf的依赖

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

3、创建一个index.html文件,并放在templates文件夹下,springboot默认会从该文件夹下寻找html文件

4、在controller中写一个方法进行测试

@Controller
public class TestController {

    @RequestMapping(value = "test")
    public String testThymeleaf(){
        System.out.println("thymeleaf");
        return "index";
    }
}

4、启动项目,访问 test路由, 发现thymeleaf已经打印出来了,页面没跳转

5、查坑记录及解决办法

  • 1) 在pom.xml中,发现有提示报错
    这里写图片描述

  • 2) 重新注释了所有依赖,重新下载,发现还是报这个错,然后页面还是一直出不来

  • 3) 最后,考虑是不是版本问题,我现在使用的springboot是2.0.0.RELEASE版本,后面我改成1.5.8.RELEASE 版本,再重新下包,就好了。。。

ps: 以后测试,还是使用最稳定的版本比较好。

猜你喜欢

转载自blog.csdn.net/fantasic_van/article/details/79691102