spring boot-9.對springMVC的支持
阿新 • • 發佈:2018-08-17
mat org dia pro eml dep 高級 pen 格式
1.thymeleaf
spring boot 推薦的模板引擎是thymeleaf。spring boot 的自動配置已經默認配置好了themleaf,只要導入themleaf的Starter就可以了。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
為了使用themleaf的高級特性,建議將themleaf版本切換至3.0以上
<properties> <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
themleaf 可以用th:開頭的所有標簽去替換原生html的相應標簽,主要的語法有以下幾個點:
(1)${...} 取變量的值,類似於OGNL
(2)#{...}:獲取國際化內容
(3)@{...}:定義URL
(4)~{...}:片段引用表達式
(5)*{...}:選擇變量表達式,功能和${}類似
themleaf 同時支持字符串操作,數學計算,比較,條件判斷,還內置了很多工具方法,如可以進行日期格式化的方法${#dates.format(date)}
spring boot-9.對springMVC的支持