SpringBoot默认不支持jsp页面
支持模板引擎 例如Velocity Freemarker Thymeleaf等
模板引擎就是将数据填充到模板中 最终生成一个页面
不同模板引擎之间的语法不相同
SpringBoot推荐Thymeleaf 语法更简单 且功能更强大
Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎
类似JSP Velocity FreeMaker等 它也可以轻易与Spring MVC等Web框架进行集成
作为Web应用的模板引擎 与其它模板引擎相比 Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面而不需要启动整个Web应用
使用
首先 当然是引入Thymeleaf的启动器(本文是在SpringBoot基础上整合Thymeleaf的 若单独使用Thymeleaf 请自行去maven仓库寻找依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
SpringBoot自动管理的Thymeleaf版本过低 需自己改版本 加在<properties>
标签内:
<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
thymeleaf3的主程序适配的是layout2以上版本
thym