3.3 Spring Boot模版引擎调用
模板引擎,是用来生成动态网页内容的,一旦控制器(Controller)收集了足够的数据,就会把数据交给模板引擎来处理,模板引擎根据数据生成HTML,返回给浏览器。
Spring Boot支持多种模板引擎,包括FreeMarker、Thymeleaf、Mustache和Groovy Templates。Spring Boot中不推荐使用jsp,Thymeleaf现在被很多人采用,它的特点就是可以直接在浏览器中打开模板文件,方便前端开发。这里选用Thymeleaf模版引擎,它的使用步骤如下:
(1)添加Thymeleaf引擎依赖:打开pom.xml,添加以下内容。
<dependencies>
......
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
......
</dependencies>
如图3-6所示。
来源:oschina
链接:https://my.oschina.net/u/4328465/blog/4406218