引入依赖

 <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}]] 条&nbsp;
每页 [[${pagination.size}]] 条&nbsp;
<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}" />&nbsp;
当前 [[${pagination.current}]]/[[${pagination.total}]] 页 &nbsp;转到第<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页面基本语法的更多相关文章

  1. Spring boot 整合jsp、thymeleaf、freemarker

    1.创建spring boot 项目 2.pom文件配置如下: <dependencies> <dependency> <groupId>org.springfra ...

  2. Spring Boot整合模板引擎thymeleaf

    项目结构 引入依赖pom.xml <!-- 引入 thymeleaf 模板依赖 --> <dependency> <groupId>org.springframew ...

  3. Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结

    Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结 这两天闲着没事想利用**Spring Boot**加上阿里的开源数据连接池**Druid* ...

  4. Spring Boot 整合 Thymeleaf 完整 Web 案例

    Thymeleaf 是一种模板语言.那模板语言或模板引擎是什么?常见的模板语言都包含以下几个概念:数据(Data).模板(Template).模板引擎(Template Engine)和结果文档(Re ...

  5. Spring Boot2 系列教程(九)Spring Boot 整合 Thymeleaf

    虽然现在慢慢在流行前后端分离开发,但是据松哥所了解到的,还是有一些公司在做前后端不分的开发,而在前后端不分的开发中,我们就会需要后端页面模板(实际上,即使前后端分离,也会在一些场景下需要使用页面模板, ...

  6. 极简 Spring Boot 整合 Thymeleaf 页面模板

    虽然现在慢慢在流行前后端分离开发,但是据松哥所了解到的,还是有一些公司在做前后端不分的开发,而在前后端不分的开发中,我们就会需要后端页面模板(实际上,即使前后端分离,也会在一些场景下需要使用页面模板, ...

  7. Spring Boot整合Thymeleaf视图层

    目录 Spring Boot整合Thymeleaf Spring Boot整合Thymeleaf 的项目步骤 Thymeleaf 语法详解 Spring Boot整合Thymeleaf Spring ...

  8. 从零开始的Spring Boot(5、Spring Boot整合Thymeleaf)

    Spring Boot整合Thymeleaf 写在前面 从零开始的Spring Boot(4.Spring Boot整合JSP和Freemarker) https://www.cnblogs.com/ ...

  9. Spring boot 整合spring Data JPA+Spring Security+Thymeleaf框架(上)

    近期上班太忙所以耽搁了给大家分享实战springboot 框架的使用. 以下是spring boot 整合多个框架的使用. 首先是准备工作要做好. 第一  导入框架所需的包,我们用的事maven 进行 ...

  10. Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客

    ==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...

随机推荐

  1. Atcoder Regular Contest 096 C - Everything on It(组合数学)

    Atcoder 题面传送门 & 洛谷题面传送门 简单题,由于这场 arc 的 F 是 jxd 作业而我不会做,所以只好来把这场的 E 水掉了. 我们记 \(f(i)\) 为钦定 \(i\) 个 ...

  2. R语言与医学统计图形-【15】ggplot2几何对象之线图

    ggplot2绘图系统--几何对象之线图 曲线:点连线.路径曲线.时间序列曲线.模型拟合曲线...... 直线:水平直线.垂直直线.斜线. 1.曲线 对象及其参数. #路径图 geom_path(ma ...

  3. CSS浮动效果

    #div1{ background-color: yellow; width: 150px; height:150px; position: absolute; top:150px; left: 15 ...

  4. 完美png图片添加水印类

    完美png图片添加水印类 被添加水印图片和水印图片都可以是png,保证透明无色背景,可调节透明度 <?phpclass Imgshuiyin{ /* 缩略图相关常量定义 */ const THU ...

  5. mongoDB整个文件夹拷贝备份还原的坑

    现网有一个mongoDB数据库需要搬迁到新服务器,开发那边的要求是先搬迁现在的数据库过去,然后剩下的以后他们用程序同步. 数据库大楷20G左右,现网是主备仲裁的,停掉备点,拷贝了全部文件. 新服务器也 ...

  6. 学习java的第二十八天

    一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...

  7. binlog真的是银弹吗?有些时候也让人头疼

    大家好,我是架构摆渡人.这是实践经验系列的第三篇文章,这个系列会给大家分享很多在实际工作中有用的经验,如果有收获,还请分享给更多的朋友. binlog 用于记录用户对数据库操作的SQL语句信息,同时主 ...

  8. JDBC01 获取数据库连接

    概述 Java Database Connectivity(JDBC)直接访问数据库,通用的SQL数据库存取和操作的公共接口,定义访问数据库的标准java类库(java.sql,javax.sql) ...

  9. Hadoop、Hive【LZO压缩配置和使用】

    目录 一.编译 二.相关配置 三.为LZO文件创建索引 四.Hive为LZO文件建立索引 1.hive创建的lzo压缩的分区表 2.给.lzo压缩文件建立索引index 3.读取Lzo文件的注意事项( ...

  10. 重磅丨腾讯云开源业界首个 etcd 一站式治理平台 Kstone

    ​ Kstone 开源 在 CNCF 云原生基金会举办的2021年12月9日 KubeCon China大会上,腾讯云容器 TKE 团队发布了 Kstone etcd 治理平台开源项目. Kstone ...