Thymeleaf
- 一、Thymeleaf入门
- 二、Thymeleaf语法
- ————————
- 创作不易,如觉不错,随手点赞,关注,收藏(* ̄︶ ̄),谢谢~~
新依赖:Thymeleaf的
<!--thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
一、Thymeleaf入门
什么是Thymeleaf?
Thymeleaf就是模板引擎,我们其实大家听到很多,其实jsp就是一个模板引擎,还有用的比较多的freemarker,包括SpringBoot给我们推荐的Thymeleaf,模板引擎有非常多,但再多的模板引擎,他们的思想都是一样的。
这里我们使用Thymeleaf模板引擎
看一下源码,注意这个路径 “classpath:/templates/”; “.html”; 存放html的
@ConfigurationProperties(
prefix = "spring.thymeleaf"
)
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING;
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
private boolean checkTemplate = true;
private boolean checkTemplateLocation = true;
private String prefix = "classpath:/templates/";
private String suffix = ".html";
private String mode = "HTML";
private Charset encoding;
}
1、首先,导入Thymeleaf依赖

2、创建一个测试页面,导入约束

3、写一个Controller

4、运行,看一下,数据能取到,OK。

二、Thymeleaf语法
看图,常用的

1、演示几个,Controller存入数据:

2、页面取

3、运行看一下,没有问题




















