开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第19天,点击查看活动详情
1.学习目标
1)熟悉Thymeleaf模板引擎基本语法
2)熟悉Spring Boot模板配置和静态资源映射规则
3)掌握Spring Boot整合Thymeleaf模板引擎使用
4)掌握Spring Boot国际化功能实现
2.SpringBoot框架的概要
1.Spring Boot框架为简化项目的整体开发,对一些常用的视图技术实现了整合支持,并主要推荐整合模板引擎技术来实现前端页面的动态化内容。
2.Spring Boot可整合的模板引擎技术:
3.Thymeleaf 模板引擎的设计思想
4.引入Thymeleaf
5.Thymeleaf 常用标签
6.Thymeleaf 主要语法
7.Thymeleaf 常用标签(示例代码)
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="all"
href="../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
<title>Title</title>
</head>
<body>
<p th:text="#{hello}">欢迎进入Thymeleaf的学习</p>
</body>
</html>
8.Thymeleaf 为变量所在域提供了一些内置对象
3.Thymeleaf基本使用
1.在SpringBoot项目中必须要引入如下的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.其次在全局配置文件中配置Thymeleaf模板的一些参数。如设置模板缓存、模板编码、模板样式、指定模板页面存放路径、指定模板页面名称的后缀。
spring.thymeleaf.cache = true
spring.thymeleaf.encoding = UTF-8
spring.thymeleaf.mode = HTML5
spring.thymeleaf.prefix = classpath:/templates/
spring.thymeleaf.suffix = .html
3.SpringBoot中静态资源的访问路径
4.Spring Boot 中静态资源的映射规则(原理)
5.Spring Boot 中静态资源的映射规则
开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第19天,点击查看活动详情