引入依赖

 <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. R同时保存png/pdf等格式图片

    R怎么同时保存png/pdf等多种格式的图片? 如果是ggplot对象,用ggsave用两下就行,如果不是呢? png/pdf()组合dev.off()是通常保存方法,但一个组合只能保存一个图片.要想 ...

  2. Linux—查看内核版本、系统版本、系统位数

    一.查看内核版本命令: 1) [root@q1test01 ~]# cat /proc/version   Linux version 2.6.9-22.ELsmp (bhcompile@crowe. ...

  3. 非线性回归支持向量机——MATLAB源码

    支持向量机和神经网络都可以用来做非线性回归拟合,但它们的原理是不相同的,支持向量机基于结构风险最小化理论,普遍认为其泛化能力要比神经网络的强.大量仿真证实,支持向量机的泛化能力强于神经网络,而且能避免 ...

  4. Oracle完整的压测记录

    问题描述:对oracle进行一次完整的数据压测,从制造数据到压测的过程,路上踩了一些坑,现在分享出来 1.下载swingbenh软件,一个比较好用的oracle压测软件 2.利用oewizard工具( ...

  5. dubbo 协议的 K8s pod 存活探针配置

    背景 某项目采用微服务架构,dubbo 框架,K8s 方式部署. 其中 HTTP 协议由网关应用统一处理,大部分应用仅提供 dubbo 协议. 目标 应用某个实例(pod)状态异常时,尝试自动重启恢复 ...

  6. java类加载、对象创建过程

    类加载过程: 1, JVM会先去方法区中找有没有相应类的.class存在.如果有,就直接使用:如果没有,则把相关类的.class加载到方法区 2, 在.class加载到方法区时,会分为两部分加载:先加 ...

  7. The Ultimate Guide to Buying A New Camera

    [photographyconcentrate] 六级/考研单词: embark, thrill, excite, intimidate, accessory, comprehensive, timi ...

  8. 关于ai算法的一个点子

    长久以来,一直想要有自己的原生算法. 今天灵感图然来了: 想到, 一个事务不但要看它本身,也要看欣赏它的人. 要研究两个方面. 你要研究音乐,也要研究欣赏音乐的人. 人之所以会欣赏音乐,而牛不可以(对 ...

  9. Shell学习(八)——dd命令

    一.dd命令的解释 dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:b=512:c=1:k=1024:w=2 参数注释: 1. ...

  10. SpringCloud微服务-Eureka服务注册与发现

    一. Eureka 是什么? Eureka是Netflix的一个子模块,也是核心模块之一.Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对微服务 ...