首页 > 其他分享 >Springboot 整合 thymeleaf-1

Springboot 整合 thymeleaf-1

时间:2022-10-31 15:07:44浏览次数:68  
标签:Springboot spring boot thymeleaf html 整合 添加 页面


文章目录

  • ​​thymeleaf百叶香​​
  • ​​一、添加依赖​​
  • ​​1.创建项目的时候引入依赖​​
  • ​​2.直接在pom里面添加依赖​​
  • ​​二、建立页面html 并添加命名空间​​
  • ​​三、配置properties​​
  • ​​四、书写html​​

thymeleaf百叶香

一、添加依赖

1.创建项目的时候引入依赖

Springboot 整合 thymeleaf-1_spring

2.直接在pom里面添加依赖

<!--SpringBoot 集成 Thymeleaf 的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--SpringBoot 开发 web 项目的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

二、建立页面html 并添加命名空间

<html xmlns:th="http://www.thymeleaf.org">

Springboot 整合 thymeleaf-1_spring_02

Springboot 整合 thymeleaf-1_缓存_03

三、配置properties

thymeleaf 页面的缓存开关,默认 true 开启缓存
#建议在开发阶段关闭 thymeleaf 页面缓存,目的实时看到页面
spring.thymeleaf.cache=false
其实什么都不用配置就可以工作,因为基本 Thymeleaf 的配置都有默认值
前缀:
#thymeleaf 模版前缀,默认可以不写
spring.thymeleaf.prefix=classpath:/templates/
后缀:
#thymeleaf 模版后缀,默认可以不写
spring.thymeleaf.suffix=.html

关闭缓存

Springboot 整合 thymeleaf-1_html_04

四、书写html

Springboot 整合 thymeleaf-1_缓存_05


Springboot 整合 thymeleaf-1_缓存_06


标签:Springboot,spring,boot,thymeleaf,html,整合,添加,页面
From: https://blog.51cto.com/u_15854304/5809744

相关文章