Thymeleaf和Fremarker一样是静态模板,两者整合方式相似,使用的时候二者选择其一即可,整合步骤如下:
1,在pom.xml中引入Thymeleaf的依赖

2,在application.properties中进行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,测试

结果如下:


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