模板引擎

SpringBoot与web开发(二)-----Thymeleaf 模板引擎

模板引擎 Thymeleaf

Thymeleaf 模板引擎 1. 引入Thymeleaf <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> @ConfigurationProperties(prefix = "spring.thymeleaf") public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html"; 将html页面放在templates目录下使用模板引擎 渲染页面 html中引入 <html lang="en" xmlns:th="http://www.thymeleaf.org"> 2. 语法规则 来自官网的使用手册:http://www.thymeleaf.org th 语法 表达式 Simple expressions:(表达式语法) Variable Expressions: ${...}:获取变量值;OGNL; 1)、获取对象的属性、调用方法 2)、使用内置的基本对象: #ctx : the context object. #vars: the context variables.