SpringBoot极简教程 · Spring Boot SpringBoot之路

Springnboot整合Thymeleaf

2018-07-21  本文已影响17人  懒小松

Thymeleaf和Fremarker一样是静态模板,两者整合方式相似,使用的时候二者选择其一即可,整合步骤如下:

1,在pom.xml中引入Thymeleaf的依赖

thymeleaf模板依赖

2,在application.properties中进行thymeleaf模板配置

thymeleaf资源配置

3,创建静态模板,后缀为.html

纯静态模板 接收后台属性模板

在这里需要注意一点,如果没有在第一行内引入 "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd",并且在html内没有写xmlns="http://www.w3.org/1999/xhtml"       xmlns:th="http://www.thymeleaf.org"这两句时,在idea中使用thymeleaf的静态标签会显示报错。

4,测试

thymeleaf测试

结果如下:

项目案例已经放在GitHub上,有兴趣的同学可以访问https://github.com/poppetman/springbootdemo进行项目下载。

上一篇 下一篇

猜你喜欢

热点阅读