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 ...
随机推荐
- BZOJ 3453 - tyvj 1858 XLkxc(插值+推式子)
题面传送门 首先根据我们刚学插值时学的理论知识,\(f(i)\) 是关于 \(i\) 的 \(k+1\) 次多项式.而 \(g(x)\) 是 \(f(x)\) 的前缀和,根据有限微积分那一套理论,\( ...
- 洛谷 P4062 - [Code+#1]Yazid 的新生舞会(权值线段树)
题面传送门 题意: 给出一个序列 \(a\),求 \(a\) 有多少个子区间 \([l,r]\),满足这个区间中出现次数最多的数出现次数 \(>\dfrac{r-l+1}{2}\) \(1 \l ...
- Codeforces 505E - Mr. Kitayuta vs. Bamboos(二分+堆)
题面传送门 首先很显然的一点是,看到类似于"最大值最小"的字眼就考虑二分答案 \(x\)(这点我倒是想到了) 然鹅之后就不会做了/wq/wq/wq 注意到此题正着处理不太方便,故考 ...
- 自定义 Word 模板
自定义 Word 模板 目录 必要设置 样式设置 标题样式 多级列表 封面 正文 引用目录 页码 页眉 图标 自定义模板保存 样式导入和导出 批量删除多余空白段落 必要设置 显示所有格式标记 选择&q ...
- expr计算字符串长度
命令:expr length "quanzhiqinag" #!/bin/bash for N in quan zhi qiang do if [ `expr length $N ...
- 【shell】真正解决syntax error:unexpected end of file?
今天写了个较长的shell脚本,结构嵌套比较多,最后运行时,出现了syntax error: unexpected end of file的错误. 这个之前碰到过,经常在win系统转移脚本文件到uni ...
- linux下vim的安装与配置(centos)
1.vim的安装 #yum search vim //查看vim相关软件信息 #yum install -y vim* //在线安装vim 2.vim的配置 (1)~/.viminfo 在vim ...
- Redis学习小结
在7月中旬,我成功入职实习,通过进入公司,认识到了个人与企业巨大的差距,首先就是对于中间件的使用,ElasticSearch.Redis.Kafka等等,都是听过却从未使用过的,然而在任务下达之后,激 ...
- 【每天五分钟大数据-第一期】 伪分布式+Hadoopstreaming
说在前面 之前一段时间想着把 LeetCode 每个专题完结之后,就开始着手大数据和算法的内容. 想来想去,还是应该穿插着一起做起来. 毕竟,如果只写一类的话,如果遇到其他方面,一定会遗漏一些重要的点 ...
- 入坑不亏!我们最终决定将 70w+ 核心代码全部开源
作者 | 一啸 来源 | 尔达 Erda 公众号 背景故事 2017 年初,我们基于 DC/OS (mesos + marathon) 开始构建端点自己的 PaaS 平台,核心任务就是解决公司的软件开 ...