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 ...
随机推荐
- Codeforces 1299D - Around the World(线性基+图论+dp)
Codeforces 题目传送门 & 洛谷题目传送门 一道线性基的综合题 %%%%%% 首先注意到"非简单路径""异或和"等字眼,可以本能地想到线性基. ...
- 生物信息Linux用户创建与配额设置
创建一个新用户,并配置使用. create_usr.sh: #/usr/bin/bash user=$1 password="123" useradd ${user} -g met ...
- 如何构建自己的KEGG数据库
本文转自Y叔公众号 自己KEGG数据库好处: 可重复性好 没网也可以进行分析 步骤 1 在KEGG官网找到自己物种的3字符缩写 2 加载Y叔获取kegg.db 的R包 1 ##安装Y叔的包 2 lib ...
- python包之drmaa:集群任务管理
目录 1. drmaa简介 2. 安装和配置 3. 示例 3.1 开始和终止会话 3.2 运行工作 3.3 等待工作 3.4 控制工作 3.5 查询工作状态 4. 应用 4.1 写一个简单应用 4.2 ...
- 什么是GP、LP、PE、VC、FOF?
GP GP是General Partner的缩写,意思是普通合伙人.投资者经常听到的一些基金.风投等投资公司采用的就是普通合伙人的制度,在美国等发达国家,普通合伙人很常见. 其实,说白了,GP最开始指 ...
- C++栈溢出
先看一段代码 #include<iostream> using namespace std; #define n 510 void sum(int a,int b) { cout<& ...
- 学习java 7.19
学习内容: 接口的组成中加入了默认方法,静态方法,私有方法 接口中默认方法:public default 返回值类型 方法名(参数列表){ } public default void show() ...
- 面对大规模 K8s 集群,这款诊断利器必须要“粉一波”!
作者|段超 来源|尔达 Erda 公众号 背景 我们是一家做商业软件的公司,从一开始我们就把软件交付流程做的非常标准且简单,所有的软件都是基于我们的企业数字化平台 Erda(现已开源)来交付,底层基于 ...
- android Paint 详解
/** * Paint类介绍 * * Paint即画笔,在绘图过程中起到了极其重要的作用,画笔主要保存了颜色, * 样式等绘制信息,指定了如何绘制文本和图形,画笔对象有很多设置方法, * 大体 ...
- Linux lvm在线扩容
1.查看磁盘空间 [root@bgd-mysql3 ~]# fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sector ...