SpringBoot之Thymeleaf简要基础知识

SpringBoot支持的视图技术之Thymeleaf

1、SpringBoot可整合的模板引擎技术

(1)FreeMarker
(2)Groory
(3)Thymeleaf
(4)Mustache
  等等

2、Thymeleaf常用标签(示例代码)

<!DOCTYPE html>
<html lang = "en" xmlns:th="http://www.thymeleaf.org">  #引入thymeleaf标签
<head>
    <meta charset = "UTF-8">
    <meta name = "viewport" content = "width = device - width, initial - scale = 1.0">
    <meta http-equiv = "X-UA-Compatible" content = "ie-edge">
    <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}">Hello world</p>
</body>
</html>

3、Thymeleaf主要语法

变量表达式

  ${...}   //获取上下文中的变量值  

选择变量表达式

  *{...}   //用于从被选定的对象获取属性值

消息表达式

  #{...}  //用于Thymeleaf模板页面国际化内容的动态替换和展示

链接URL表达式

  @{...}  //用于页面跳转或者资源的引入

片段表达式

  ~{...}  //用来标记一个片段模板,并根据需要移动或传递给其他模板

4、Thymeleaf基本使用

4.1 在SpringBoot项目中使用Thymeleaf模板,必须保证引入Thymeleaf依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf<artifactId>
</dependency>

4.2 其次在全局配置文件中配置Thymeleaf模板的一些参数。(如设置模板缓存、模板编码、模板样式、指定模板页面存放路径、指定模板页面名称的后缀)

#模板缓存开启
spring.thymeleaf.cache=true

#模板编码
spring.thymeleaf.encoding=UTF-8

#模板样式
spring.thymeleaf.mode=HTML5

#指定模板页面存放路径
spring.thymeleaf.prefix=classpath:/templates/

#指定模板页面名称的后缀
spring.thymeleaf.suffix=.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

熊凯瑞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值