初識springboot 引入thymeleaf

2021-10-04 20:17:03 字數 1189 閱讀 5714

因為springboot不支援jsp

使用模板引擎

寫乙個頁面模板,和資料交給模板,生成乙個頁面。

推薦thymeleaf

語法簡單功能強大,

1.引入thymeleaf

org.springframework.boot

spring-boot-starter-thymeleaf

修改版本:

1.8

3.0.9.release

2.2.2

2.使用語法:

按照自動配置規則來使用

只要我們把html頁面放在templates裡,就能自動渲染了,

在html檔案中使用thymeleaf呼叫

首先匯入thyme leaf提示

使用thymeleaf的語法

th:text="":將div中文字內容設定為指定內容
語法規則:

th:任意html屬性,就可以直接在後台之類的取值

片段包含:

th:insert 

th:replace

遍歷:th:each

條件判斷:th:if

th:switch

th:unless

th:case

變數宣告

th:object

th:with

屬性修改

th:attr

th:attrprepend

修改指定屬性:

th:value

th:href

th:src

修改標籤體內容

th:text

th:utext  不轉義特殊字元

宣告片段

th:fragmen

移除th:remove

2.表示式

${}獲取變數值,獲取物件的屬性,呼叫方法,使用內建基本物件,內建的工具物件。

*{}選擇表示式和${}差不多但是有補充,

#{}國際化內容

@{}定義url鏈結的

~{}片段引用的表示式

//users的值賦給user了然後顯示

[[$]]//這個直接代表th:text

springBoot引入spring配置檔案

springboot中新增或更改預設配置,基本是使用 configuration bean component等註解來實現,和之前的spring中的xml配置檔案配置的方式完全不同。需注意 springboot中也可以載入原始的xml配置檔案的方式來配置spring。比如,作者之前在使用spring...

Spring Boot 專案中引入 flyway

org.flywaydb flyway core 5.2.4 flyway spring.flyway.baseline on migrate true spring.flyway.baseline description flyway baseline 禁止刪除 schema 下的 table s...

springboot引入配置的幾種方式

第一種方式 之前有說到用註解 configurationproperties,去.properties和.yaml讀取屬性,進行物件的初始化 所有用以下方式 component configurationproperties prefix person propertysource value va...