Spring Boot整合Thymeleaf及Thymeleaf页面基本语法
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.7.RELEASE</version>
</dependency>
application.yml文件
spring:
thymeleaf:
cache: false
encoding: utf-8
mode: HTML5
suffix: .html
默认页面后缀为.html 路径为templates文件夹下
然后我们在templates 创建一个 info.html页面
后台控制器写法
@RequestMapping(value = "/index")
public String index() {
return "info";
}
这里的info就是templates下的info.html页面的文件名
----------------------------一些页面基础用法-------------------------
页面集合遍历
<tr th:each="o,index : ${List}">
<td th:text="${index.index+1}">Tanmay</td>
<td th:text="${o.nickName}">Tanmay</td>
<td th:text="${o.mobile}">Bangalore</td>
<td th:text="${o.totalView}">560001</td>
</tr>
变量和常量拼接
<span th:text="${percent}+'%'">40%</span>
字符串是否是null
<div th:if="${msg} != null"></div>
判断是不是为空字符串
<span th:if="${#strings.isEmpty(msg)}">空的</span>
页面引入
在index.html页面引入其他页面footer.html (默认页面都在templates文件夹下)
1、把foot页面用
<div th:fragment="footer">
footer页面的html代码
</div>
2、然后在index.html中写
<th:block th:include="footer :: footer" />
注:这里的第一个footer是指footer.html页面 从templates文件夹开始算起,如果footer.html页面在 templates的include文件夹下,那么这里就换成 include/footer
第二个footer是指footer.html中的 th:fragment=“footer”这里的标签名称 然后就会把这个div中包含的html代码块替换到 我们写的index.html的 <th:block >标签的位置
日期格式化
<span th:text="${#dates.format(content.createTime,'yyyy-MM-dd HH:mm:ss')}"></span>
分页demo
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" class="pn-sp">
共 [[${pagination.total}]] 条
每页 [[${pagination.size}]] 条
<input type="button" value="首 页" onclick="_gotoPage('1');" th:disabled="${pagination.current} ==1"/>
<input type="button" value="上一页" th:onclick="_gotoPage('[[${pagination.current}-1]]');" th:disabled="${pagination.current} ==1" />
<input type="button" value="下一页" th:onclick="_gotoPage('[[${pagination.current}+1]]');" th:disabled="${pagination.current} ==${pagination.pages}" />
<input type="button" value="尾 页" th:onclick="_gotoPage('[[${pagination.pages}]]');" th:disabled="${pagination.current} ==${pagination.pages}" />
当前 [[${pagination.current}]]/[[${pagination.total}]] 页 转到第<input type="text" id="_goPs" onfocus="this.select();" onkeypress="if(event.keyCode==13){$('#_goPage').click();return false;}" style="width:50px; border:1px solid #e7e7e7;"/>页
<input id="_goPage" type="button" value="转" onclick="_gotoPage($('#_goPs').val());" th:disabled="${pagination.pages} ==1" />
</td>
</tr>
</table> <script type="text/javascript">
function _gotoPage(pageNo) {
try {
var tableForm = document.getElementById("tableForm");
$("input[name=pageNo]").val(pageNo);
tableForm.onsubmit = null;
tableForm.submit();
} catch (e) {
console.log(e);
alert('_gotoPage(pageNo)方法出错');
}
}
</script>
html列表中有
<form th:action="@{'/member/channel/list/'+${channel.channelId}}" id="tableForm">
<input type="hidden" name="pageNo"/>
</form>
后台
IPage<Content> pagination = contentService.page(page, queryWrapper);
model.addAttribute("pagination", pagination);
页面标签disabled 判断
th:disabled="${pagination.current} ==1"
控制display 是否显示 (满足条件显示)
th:style="'display:' + @{(${status!=null} ? 'inline-block' : 'none')} + ''"
按指定字符分割字符串然后遍历
<div class="col-xs-12 col-md-12" th:each="item,state:${#strings.arraySplit(content.outLink,',')}">
<a th:href="${item}" target="_blank">[[${state.index+1}]]、[[${item}]]</a>
</div>
Spring Boot整合Thymeleaf及Thymeleaf页面基本语法的更多相关文章
- Spring boot 整合jsp、thymeleaf、freemarker
1.创建spring boot 项目 2.pom文件配置如下: <dependencies> <dependency> <groupId>org.springfra ...
- Spring Boot整合模板引擎thymeleaf
项目结构 引入依赖pom.xml <!-- 引入 thymeleaf 模板依赖 --> <dependency> <groupId>org.springframew ...
- Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结
Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结 这两天闲着没事想利用**Spring Boot**加上阿里的开源数据连接池**Druid* ...
- Spring Boot 整合 Thymeleaf 完整 Web 案例
Thymeleaf 是一种模板语言.那模板语言或模板引擎是什么?常见的模板语言都包含以下几个概念:数据(Data).模板(Template).模板引擎(Template Engine)和结果文档(Re ...
- Spring Boot2 系列教程(九)Spring Boot 整合 Thymeleaf
虽然现在慢慢在流行前后端分离开发,但是据松哥所了解到的,还是有一些公司在做前后端不分的开发,而在前后端不分的开发中,我们就会需要后端页面模板(实际上,即使前后端分离,也会在一些场景下需要使用页面模板, ...
- 极简 Spring Boot 整合 Thymeleaf 页面模板
虽然现在慢慢在流行前后端分离开发,但是据松哥所了解到的,还是有一些公司在做前后端不分的开发,而在前后端不分的开发中,我们就会需要后端页面模板(实际上,即使前后端分离,也会在一些场景下需要使用页面模板, ...
- Spring Boot整合Thymeleaf视图层
目录 Spring Boot整合Thymeleaf Spring Boot整合Thymeleaf 的项目步骤 Thymeleaf 语法详解 Spring Boot整合Thymeleaf Spring ...
- 从零开始的Spring Boot(5、Spring Boot整合Thymeleaf)
Spring Boot整合Thymeleaf 写在前面 从零开始的Spring Boot(4.Spring Boot整合JSP和Freemarker) https://www.cnblogs.com/ ...
- Spring boot 整合spring Data JPA+Spring Security+Thymeleaf框架(上)
近期上班太忙所以耽搁了给大家分享实战springboot 框架的使用. 以下是spring boot 整合多个框架的使用. 首先是准备工作要做好. 第一 导入框架所需的包,我们用的事maven 进行 ...
- Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
随机推荐
- Linux服务器查看个人硬盘配额
quota -uvs
- PHP安装PDO_MySQL模块
下载pdo_mysql扩展 wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz 解压压缩包 tar -zxvf PDO_MYSQL-1.0.2.tgz 执 ...
- 【ThermoRawFileParser】质谱raw格式转换mgf
众所周知,Proteowizard MSconvert用于质谱原始数据的格式转换,但主要平台是windows,要想在Linux上运行需要打Docker或Wine,对于普通用户来说还是很困难的,想想质谱 ...
- 【R】如何去掉数据框中包含非数值的行?
目录 1. 去掉指定列中包含NA/Inf/NaN的行 2. 去掉指定列中包含其他乱七八糟字符串的行 3. 去掉整个数据框中包含非数值的行 只包含NA.NaN和Inf的情况 针对其他字符情况 4. 总结 ...
- nginx二级域名指向不同文件项目配置
需要使用泛域名解析, 并且加上空的判断,以保证没有二级域名的也可以访问 核心配置 server_name ~^(?<subdomain>.+)\.caipudq\.cn$;if ( $su ...
- Flink(三)【核心编程】
目录 一.Environment 二.Source 从集合读取数据 从文件读取数据 从kakfa读取数据(常用) 自定义数据源 三.Transform map Rich版本函数 flatMap key ...
- 数仓day03-----日志预处理
1. 为什么要构建一个地理位置维表(字典) 在埋点日志中,有用户的地理位置信息,但是原始数据形式是GPS坐标,而GPS坐标在后续(地理位置维度分析)的分析中不好使用.gps坐标的匹配,不应该做这种精确 ...
- Oracle中常用的系统函数
本文主要来梳理下Oracle中的常用的系统函数,掌握这些函数的使用,对于我们编写SQL语句或PL/SQL代码时很有帮助,所以这也是必须掌握的知识点. 本文主要包括以下函数介绍:1.字符串函数2. 数值 ...
- 转 Android 多线程:手把手教你使用AsyncTask
转自:https://www.jianshu.com/p/ee1342fcf5e7 前言 多线程的应用在Android开发中是非常常见的,常用方法主要有: 继承Thread类 实现Runnable接口 ...
- SVN的基本介绍\服务器配置
### 1. 工作场景 1. 进入公司需要做的关于开发的第一件事, 就是向项目经理索要SVN服务器地址+用户名+密码### 2. 角色解释> 服务器: 用于存放所有版本的代码,供客户端上传下载更 ...