前言

Thymeleaf 是 Spring 官方文档里默认的模板引擎,最大的卖点是原生 HTML 模板:模板文件不经过引擎也能直接用浏览器打开看排版,设计稿改改就能当模板用。FreeMarker 那套见 接入指南 和 语法详解,这篇给 Thymeleaf 同样的一套。

1、引入依赖

1
2
3
4
5
6
7
8
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

模板默认放 classpath:/templates/,后缀 .html。

……

阅读全文