03-03:springBoot 整合thymeleaf
thymeleaf 语法详解
1.变量输出:
th:text :在页面中输出某个值
th:value :将一个值放到input标签中的value中。
2.判断字符串是否为空
①:调用内置对象一定要用#
②:大部分的内置对象都已s结尾(strings,numbers,dates)
${#strings.isEmpty(msg)}:判断字符串是否为空,如果为空返回true 否则返回false
${#strings.contains(msg,'T')} :判断字符串是否包含指定的子串,如果包含返回 true,否则返回 false
${#strings.startsWith(msg,'a')}:判断当前字符串是否以子串开头,如果是返回 true,否则返回 false
${#strings.endsWith(msg,'a')}:判断当前字符串是否以子串结尾,如果是返回 true,否则返回 false
${#strings.length(msg)}:返回字符串的长度
${#strings.indexOf(msg,'h')}:查找子串的位置,并返回该子串的下标,如果没找到则返回-1
${#strings.substring(msg,13)}:截取子串,用户与 jdk String 类下 SubString 方法相同
${#strings.substring(msg,13,15)}:截取子串,用户与 jdk String 类下 SubString 方法相同
${#strings.toUpperCase(msg)}:字符串转大小写。
${#strings.toLowerCase(msg)}:字符串转大小写。
3.日期格式化处理
${#dates.format(key)}:格式化日期,默认的以浏览器默认语言为格式化标准
${#dates.format(key,'yyy/MM/dd')}:按照自定义的格式做日期转换
${#dates.year(key)}:year:取年
${#dates.month(key)}:Month:取月
${#dates.day(key)}:Day:取日
4.条件判断
①:th:if
<span th:if="${sex} == '男'"> 性别:男 </span>
<span th:if="${sex} == '女'"> 性别:女 </span>
②:th:switch
<div th:switch = "${id}" >
<span th:case = "1">1</span>
<span th:case = "2">2</span>
<span th:case = "3">3</span>
</div>
5.迭代遍历(对集合的遍历)
①:th:each
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr th:each="u : ${list}">
<td th:text="${u.userid}"></td>
<td th:text="${u.username}"></td>
<td th:text="${u.userage}"></td>
</tr>
</table>
②:th:each 状态变量
1.index 当前迭代器的索引,从0开始
2.count 当前迭代对象的计数,从1开始
3.size 被迭代对象的长度
4.even/odd:布尔值,当前循环是否是偶数/奇数 从 0 开始
5.first:布尔值,当前循环的是否是第一条,如果是返回 true 否则返回 false
6.last:布尔值,当前循环的是否是最后一条,如果是则返回 true 否则返回 false
③.th:each 迭代Map
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr th:each="maps : ${map}">
<td th:each="entry:${maps}" th:text="${entry.value.userid}" ></td>
<td th:each="entry:${maps}" th:text="${entry.value.username}"></td>
<td th:each="entry:${maps}" th:text="${entry.value.userage}"></td>
</tr>
</table>
6.域对象操作
1.httpServletRequest
7.URL表达式
th:herf
th: src
①:url表达式语法
@{} 基本语法构成
②:URL类型
1.绝对路径
<a th:href="@{http://www.baidu.com}" >绝对路径1</a>
2.相对路径
一、相对于当前项目的根(相对于项目的上下文的相对路径)
<a th:href="@{show}">相对路径</a>
二、相对于服务器路径的根
<a th:href="@{~/project/recousename}">相对服务器的根路径</a>
③:在URL中实现参数的传递
1.<a th:href="@{show(id=1,name=wj)}">传参</a>
④:在url中通过restful方式进行参数的传递
1.<a th:href="@{show/{id}/(id=1,name=wj)}">传参-restful</a>
03-03:springBoot 整合thymeleaf的更多相关文章
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- 三、SpringBoot整合Thymeleaf视图
目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...
- SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目
如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...
- SpringBoot 整合thymeleaf
1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...
- springboot整合thymeleaf+tiles示例
网上关于此框架的配置实在不多,因此想记录下来以防忘记 因为公司框架基于上述(公司采用gradle构建项目,楼主采用的是maven),所以楼主能少走些弯路: 1.创建springboot-maven项目 ...
- SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
- springboot整合Thymeleaf模板引擎
引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...
- SpringBoot学习9:springboot整合thymeleaf
1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewo ...
- SpringBoot整合Thymeleaf
一个整合Thymeleaf与Mybatis的CRUD例子 整合Mybatis例子 一.添加maven依赖 <dependency> <groupId>org.springfra ...
随机推荐
- 微信小程序之跨界面传参
微信小程序在两个之间传参类似js传递url拼接参数,举个例子来说吧 input自己设置参数 //index.wxml <form bindsubmit="formSubmit" ...
- GDAL读写矢量文件——Python
在Python中使用OGR时,先要导入OGR库,如果需要对中文的支持,还需要导入GDAL库,具体代码如下.Python创建的shp结果如图1所示. 图1 Python创建矢量结果 #-*- codin ...
- 2018-03-10 VCard备份恢复联系人
主要在VCardComposer类中备份联系人的逻辑 导出流程: http://blog.csdn.net/michael_yt/article/details/78270537 导入流程: http ...
- (转)JDK安装配置教程
转自:http://jingyan.baidu.com/article/bea41d435bc695b4c41be648.html JDK作为JAVA开发的环境,不管是做JAVA开发的学生,还是做安卓 ...
- Libre Office冻结操作-MAC
冻结行/列 选中所要冻结的行/列,选择window-Freeze 冻结成功 冻结单元格 操作方法与“冻结行/列”一致
- html部分常用标签的含义及作用
1.a 超链接 <a> 标签定义超链接,用于从一张页面链接到另一张页面.<a> 标签中必须提供 href 属性或 name 属性,它指示链接的目标. 例如:点击 百度一下 跳转 ...
- QT源码查看001-QApplication和QCoreApplication
QCoreApplication和QApplication的区别(1) QApplication这个类是继承QCoreApplication的,而QCoreApplication有继承QObject的 ...
- poj2094
很不错的一道题,很让我见识到了差分序列的运用的神奇之处..一下是从北邮BBS看到的题解,写得很清楚..这边就直接转过来. uRLhttp://bbs.byr.cn/#!article/ACM_ICPC ...
- [置顶] 获取网络数据中的数组显示成ListView的简单流程
首先说一下 这是我自己的个人笔记,如果想看看,不用看细节,可以看流程. 定义一个线程池 ExecutorService pool = Executors.newFixedThreadPool(15) ...
- rsync+sersync+inotify实现服务器间文件同步之一
rsync+sersync+inotify实现服务器间文件同步之一:rsync安装配置 2013年12月14日 ⁄ Linux管理, 服务器集群技术 ⁄ 共 4925字 ⁄ rsync+sersync ...