当前位置:网站首页>Thymeleaf的配置
Thymeleaf的配置
2022-06-27 11:56:00 【瑾琳】
Thymeleaf是动态才会显示出功能的
build.gradle详细解释 增加Thymeleaf依赖
// buildscript 代码块中脚本优先执行
buildscript {
// ext 用于定义动态属性
ext {
springBootVersion = '1.5.2.RELEASE'
}
// 自定义 Thymeleaf 和 Thymeleaf Layout Dialect 的版本
ext['thymeleaf.version'] = '3.0.3.RELEASE'
ext['thymeleaf-layout-dialect.version'] = '2.2.0'
// 使用了 Maven 的中央仓库(你也可以指定其他仓库)
repositories {
//mavenCentral()
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}
// 依赖关系
dependencies {
// classpath 声明说明了在执行其余的脚本时,ClassLoader 可以使用这些依赖项
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
// 使用插件
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
// 打包的类型为 jar,并指定了生成的打包的文件名称和版本
jar {
baseName = 'thymeleaf-in-action'
version = '1.0.0'
}
// 指定编译 .java 文件的 JDK 版本
sourceCompatibility = 1.8
// 默认使用了 Maven 的中央仓库。这里改用自定义的镜像库
repositories {
//mavenCentral()
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}
// 依赖关系
dependencies {
// 该依赖对于编译发行是必须的
compile('org.springframework.boot:spring-boot-starter-web')
// 添加 Thymeleaf 的依赖
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
// 该依赖对于编译测试是必须的,默认包含编译产品依赖和编译时依
testCompile('org.springframework.boot:spring-boot-starter-test')
}
如果是用cmd来运行,gradlew bootRun
在src/main/resources下的application.properties写
#Thymeleaf源码
spring.thymeleaf.encoding=UTF-8
#热部署静态文件 (实时改变)
spring.thymeleaf.cache=false
#使用HTML5标准
spring.thymeleaf.mode=HTML5
这样就配置完成了
后端代码这里不做演示
前端
把html文件放在src/main/resources下的templates下 可以在templates下创建文件夹(创建共用html所放的文件夹fragments和users)
把css,js,images放在src/main/resources下的static中
header.html
<!DOCTYPE html>
<!-- 下面是引用方言-->
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title th:text="${userModel.title}">welcome</title>
</head>
<body>
<div th:fragment="header">
<h1>Hello world</h1>
<a th:href="@{~/users}">首页</a>
</div>
</body>
</html>
list.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title th:text="${userModel.title}">welcome</title>
</head>
<body>
<!-- 下面写的是fragments文件夹下的header文件 里的header-->
<div th:replace="~{fragments/header :: header}">...</div>
<h3 th:text="${userModel.title}">Welcome to waylau.com</h3>
<div>
<a href="/users/form.html" th:href="@{~/users/form}">创建用户</a>
</div>
<table border="1">
<thead>
<tr>
<td>ID</td>
<td>Age</td>
<td>Name</td>
</tr>
</thead>
<tbody>
<tr th:if="${userModel.userList.size()} eq 0">
<td colspan="3">没有用户信息!!</td>
</tr>
<tr th:each="user : ${userModel.userList}">
<td th:text="${user.id}">1</td>
<td th:text="${user.age}">11</td>
<td><a href="view.html" th:href="@{'/users/' + ${user.id}}"
th:text="${user.name}">waylau</a></td>
</tr>
</tbody>
</table>
<div th:replace="~{fragments/footer :: footer}">...</div>
</body>
</html>
form.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title th:text="${userModel.title}">users : View</title>
</head>
<body>
<div th:replace="~{fragments/header :: header}">...</div>
<h3 th:text="${userModel.title}">Welcome</h3>
<div>
<a href="/users">返回主页</a>
</div>
<form action="/users" method="POST" th:object="${userModel.user}">
<input type="hidden" name="id" th:value="*{id}">
名称:<br>
<input type="text" name="name" th:value="*{name}">
<br>
年龄:<br>
<input type="text" name="age" th:value="*{age}">
<input type="submit" value="提交">
</form>
<div th:replace="~{fragments/footer :: footer}">...</div>
</body>
</html>
边栏推荐
- C # WPF realizes undo redo function
- uniapp下拉弹层选择框效果demo(整理)
- Getting started with go web programming: validators
- Topic38——56. 合并区间
- Nvme2.0 protocol - new features
- R language dplyr package arrange function sorts dataframe data, sorts dataframe data through multiple data columns, specifies the first field to be sorted in descending order, and does not specify the
- 解开C语言的秘密《关键字》(第六期)
- 面试突击60:什么情况会导致 MySQL 索引失效?
- master公式
- MySQL high level statements (I)
猜你喜欢

Neo4j:入门基础(一)之安装与使用

mysql学习1:安装mysql

亚马逊测评掉评、留不上评是怎么回事呢?要如何应对?

JSP custom tag

How to participate in openharmony code contribution

What's the matter with Amazon's evaluation dropping and failing to stay? How to deal with it?

Excel中输入整数却总是显示小数,如何调整?
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)

Online bidding of Oracle project management system

Operators are also important if you want to learn the C language well
随机推荐
内存四区(栈,堆,全局,代码区)
R语言使用epiDisplay包的followup.plot函数可视化多个ID(病例)监测指标的纵向随访图、使用stress.labels参数在可视化图像中为强调线添加标签信息
"24 of the 29 students in the class successfully went to graduate school" rushed to the hot search! Where are the remaining five?
hibernate操作oracle数据库 主键自增
Interview shock 60: what will cause MySQL index invalidation?
Uni app sends request instructions using the escook / request miniprogram plug-in
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端
In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
Peak store app imitation station development play mode explanation source code sharing
Private dry goods sharing: how to implement platform in Enterprise Architecture
千万不要错过,新媒体运营15个宝藏公众号分享
自学ADT和OOP
MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)
Interview shock 60: what will cause MySQL index invalidation?
亚马逊测评掉评、留不上评是怎么回事呢?要如何应对?
uni-app 使用escook/request-miniprogram插件发请求说明
$15.8 billion! 2021 the world's top15 most profitable hedge fund giant
R语言fpc包的dbscan函数对数据进行密度聚类分析、plot函数可视化聚类图
一个有趣的网络掩码的实验