注:虽然现在更流行前后端分离,但是个人项目和小型项目开发和外包还是很适合mvc的一个开发模式。而且spring推荐的是thymeleaf,它和shoir、spring-security的整合配合度比较高。所以我们还是使用thymeleaf做为需要使用时的优先选择。
-
增加依赖
- 代码:
<!-- thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
这里使用springboot就不需要我们去指定版本,springboot可以指定默认的版本。
-
书写自动装配的配置
- 代码:
spring: thymeleaf: suffix: .html prefix: classpath:/templates/ mode: HTML enabled: true cache: false check-template: true encoding: UTF-8
-
修改html
- 增加声明
<html lang="zh" xmlns:th="<http://www.thymeleaf.org>">
完成。
这里只是简单的进行整合。thymeleaf的语法可以看我的博客。
也可以查看官方文档,我也是从官方文档中学出来的。