<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<html xmlsns:th="http://www.thymeleaf.org">
Thymeleaf模板默认将JS脚本、CSS样式、图片等静态文件放置在src/main/resources/static目录下。
将视图页面放在src/main/resources/templates目录下。
- 1)引入URL
<link rel="stylesheet" th:href="@{css/bootstrap.min.css}" />
<a th:href="@{http://www.baidu.com/}">百度</a>
- 2)引入图片
<img th:src="'images/'+${aBook.picture}" />
- 3)输出内容
<div th:object = "${session.user}">
<!--fistName为user对象的属性-->
name:<span th:text=" * {firstName}" ></span><br>
surname:<span th:text=" * {lastName}" ></span><br>
nationality:<span th:text=" * {nationnality}" ></span><br>
</div>
- 4)基本表达式
<p th:text="#{test.myText}" />
<!--加粗-->
<p th:utext="#{test.myText}" />
- 5)支持+、-、*、/、%等算术运算和>,<,>=,<=,==,!=等各种逻辑运算
<tr th:class="( ${row}=='even)?'even':'odd'" >...</tr>
<!--加粗-->
<p th:utext