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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

themleft模板库_Thymeleaf模板引擎常用总结

發布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 themleft模板库_Thymeleaf模板引擎常用总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一:語法簡單總結

Thymeleaf是一個Java類庫,是xml/html/html5的模板引擎,SpringBoot框架推薦在MVC的Web應用做做View層使用.

SpringBoot中整合Thymeleaf依賴如下.

org.springframework.boot

spring-boot-starter-thymeleaf

3.0.9.RELEASE

2.1.1

UTF-8

UTF-8

1.8

ThymeleafProperties的源碼如下.

將application.yml中的spring.thymeleaf的配置注入下面對應的屬性中,有幾個是默認的,剩下的都是根據使用情況配置的,然后注入到相應的值中.

@ConfigurationProperties:批量注入屬性值.

@Value:單個注入屬性值.@ConfigurationProperties(

prefix = "spring.thymeleaf"

)

public class ThymeleafProperties {

private static final Charset DEFAULT_ENCODING;

public static final String DEFAULT_PREFIX = "classpath:/templates/";

public static final String DEFAULT_SUFFIX = ".html";

private boolean checkTemplate = true;

private boolean checkTemplateLocation = true;

private String prefix = "classpath:/templates/";

private String suffix = ".html";

private String mode = "HTML";

private Charset encoding;

private boolean cache;

private Integer templateResolverOrder;

private String[] viewNames;

private String[] excludedViewNames;

private boolean enableSpringElCompiler;

private boolean enabled;

private final ThymeleafProperties.Servlet servlet;

private final ThymeleafProperties.Reactive reactive;

public ThymeleafProperties() {

this.encoding = DEFAULT_ENCODING;

this.cache = true;

this.enabled = true;

this.servlet = new ThymeleafProperties.Servlet();

this.reactive = new ThymeleafProperties.Reactive();

}

命名空間如下,靜態頁面轉換為動態視圖.

1. Thymeleaf引入css資源.

th:href="@{path}"

2. Thymeleaf引入JavaScript資源.

th:src="@{path}"

通過 "@{}"引用靜態資源.

3. 訪問Model中的數據.

${}訪問model中的屬性.

動態處理的元素使用"th:"為前綴.

4. model中的數據迭代.

判斷list集合不為空.

迭代list集合數據.list中保存實體對象.

  • 獲得名字

如何獲取遍歷列表的序號,方式一:${stat.count}是從1開始的,方式? 二:${stat.index}是從0開始的,如果從1開始就${stat.index+1}.

迭代list,里面存放map對象.

th:text=${novel['Map Key']}

5. 在JavaScript中訪問model中的數據.

通過th:inline=“javascript”添加到script標簽,這樣Javascript就可以訪問model中的對象屬性了.

通過“[[${}]]”訪問實際的值.

var single=[[${singlePerson}]];

console.log(single.name+"/"+single.age);

function getPersonName(name){

console.log(name);

}

6. 解析model屬性值中的html標簽.

7. 格式化.(表達式對象)

7.1格式化金額.小數位為2為.

350

7.2 格式化日期

28-Jun-2018

7.3 字符串連接

總結

以上是生活随笔為你收集整理的themleft模板库_Thymeleaf模板引擎常用总结的全部內容,希望文章能夠幫你解決所遇到的問題。

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