日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springboot学习日志(二)-- thymeleaf学习

發布時間:2024/9/5 编程问答 40 如意码农
生活随笔 收集整理的這篇文章主要介紹了 springboot学习日志(二)-- thymeleaf学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本次學習如何使用thymeleaf以及相關語法
1、在上一章寫的那樣 引入jar包到maven工程

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

2、同理配置yml

### springboot配置
spring:
##模板設置
thymeleaf:
prefix: classpath:/templates
suffix: .html
mode: LEGACYHTML5
encoding: utf-8
servlet:
content-type: text/html
cache: false

3、在需要引用thymeleaf添加引用頭

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

下面記錄一下thymeleaf的模板語法 和jsp稍微有些出入 不過好在不需要修改文件類型 直接將html進行頭部引用就可以使用
(1)標簽引入路徑或地址

<a th:href="@{http://www.baidu.com}"></a> //絕對路徑進行訪問
<script th:src="@{/}"></script>//相對路徑進行訪問
<link rel="stylesheet" th:href="@{css/base.css}">//默認訪問static下的文件夾
<img th:src="@{}"/>//圖片路徑引用

(2)使用變量動態替換

<div th:text="hello ${roms}">hello world</div>

使用spring想也面傳值roms:xxx即可在頁面匯總替換${roms}進行內容修改
需要注意的是 th:text 會替換掉標簽內的所有內容
(3)條件適用

//使用if進行判斷是否為真
<div th:text="hello world" th:if=${flag != true}>Login</div>
//使用unless 表示除外
<div th:text="hello world" th:unless=${flag != true}>Login</div>

(4)循環的使用

  <table>
<tr th:each="list: ${list}">
<td th:text="${list.id}">1122334</td>
<td th:text="${plistod.name}">tony</td>
</tr>
</table>

(5)工具方法使用

//日期格式化
${#dates.format(date, 'yyyy/MMM/dd HH:mm')}
//當前時間
${#dates.createNow()}
//當前日期
${#dates.createToday()}

還有其他的工具類#Calendars,#numbers,#strings,#objects,#bools,#arrays,#lists,#sets,#maps,#aggregates,#messages,#ids
詳細的api文檔可以查看官網
http://www.thymeleaf.org/doc/...

總結

以上是生活随笔為你收集整理的springboot学习日志(二)-- thymeleaf学习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。