工作中的技术总结_Thymeleaf插件_关于th:if 、th:with、th:replace和th:fragment的一些事 _20210825
工作中的技术总结_Thymeleaf _20210825
1.值取为空的情况:不能使用 th:if 进行条件渲染(因为是伪条件渲染,不管怎样元素都是先渲染到DOM再决定是否显示:个人这么认为不一定准确)可以使用带有问号的表达式 如下:
<input type="text" name="menuName" disabled th:value="${result?.data?.menuName}" class="layui-input">
<!--使用result?中的?进行处理。。-->
2.局部变量,th:with能定义局部变量:
<div th:with="firstPer=${persons[0]}">
<p>
The name of the first person is <span th:text="${firstPer.name}">Julius Caesar</span>.
</p>
</div>
当th:with被处理,firstPer变量创建一个局部变量和变量添加到map自上下文,以便它是用于评估和其他上下文中声明的变量从开始,但只有包含< div >标记的范围内。
<div th:with="firstPer=${persons[0]},secondPer=${persons[1]}">
<p>
The name of the first person is <span th:text="${firstPer.name}">Julius Caesar</span>.
</p>
<p>
But the name of the second person is
<span th:text="${secondPer.name}">Marcus Antonius</span>.
</p>
</div>
th:width属性允许重用变量定义在相同的属性:
<div th:with="company=${user.company + ' Co.'},account=${accounts[company]}">...</div>
项目中的例子:
<td style="background-color: #D0D0D0;" rowspan="2">
<div id="patternFileUpload" class="uploadFile" data-type="single" data-code="MM060"
style="width:300px;"
th:with="files=*{fileName}, fieldName='fileName', tempFiles=*{patternFileNameValue}, tempFieldName='patternFileNameValue'">
<div th:replace="common/upload :: uploadFragment"></div>
</div>
</td>
此处使用了一个模板语法
完整代码如下
<td style="background-color: #D0D0D0;" rowspan="2">
<div id="patternFileUpload" class="uploadFile" data-type="single" data-code="MM060"
style="width:300px;"
th:with="files=*{fileName}, fieldName='fileName', tempFiles=*{patternFileNameValue}, tempFieldName='patternFileNameValue'">
<div th:fragment="uploadFragment">
<style>
.upload-block {
position: relative;
text-decoration: none;
width:100%;
}
.add-btn {
float:left;
}
.pull-file {
border: 1px solid #999;
width: 80%;
color: #4a4846;
background: #dedddc;
padding: .20rem .5rem;
margin-left: 50px;
display: block;
}
.input-file {
opacity: 0;
width:100%;
position: absolute;
overflow: hidden;
right: 0;
top: 0;
}
input[type=file]::-webkit-file-upload-button{
cursor:pointer;
}
</style>
<div class="fileNameSpan" th:data-field_name="${fieldName}" th:data-temp_field_name="${tempFieldName}" th:id="'request-upload-' + ${screenType}">
<div th:if="${files != null and files.length > 0}">
<div th:each="fileName, stat : ${files}" class="old-line">
<span th:text="${#strings.substring(fileName, fileName.lastIndexOf(FILE_SEPARATOR) + 1)}"></span>
<a class="btn btn-flat-dark btn-sm" th:href="@{/common/download?(fileName=${fileName})}">
<i class="fj-icon fj-icon-download align-middle"></i>
</a>
<button type="button" class="btn btn-flat-dark btn-sm remove-conditions">
<i class="fj-icon fj-icon-remove align-middle"></i>
</button>
<input type="hidden" th:name="${fieldName+'[' + stat.index +']'}" th:value="${fileName}">
</div>
</div>
<div th:if="${tempFiles != null and tempFiles.length > 0}" >
<div th:each="tempFile, stat : ${tempFiles}" th:if="${!#strings.isEmpty(tempFile)}" class="new-line">
<span th:text="${#strings.substring(tempFile,33)}" ></span>
<button type="button" class="btn btn-flat-dark btn-sm remove-conditions">
<i class="fj-icon fj-icon-remove align-middle"></i>
</button>
<input type="hidden" th:name="${tempFieldName + '[' + stat.index +']'}" th:value="${tempFile}">
</div>
</div>
</div>
<div class="upload-block">
<span class="btn btn-sm btn-primary add-btn">追加</span>
<span class="pull-file">点击获取文件</span>
<input type="file" name="formFile" class="input-file" style="cursor:pointer;">
</div>
</div>
</div>
</td>
这里的功能是实现从后端获取文件名或者路径列表并枚举出来,还提供了追加文件的功能,具体的没有仔细看。
3. thymeleaf 模板语法
对代码块进行命名即可引用,命名方法如下
<div th:fragment="uploadFragment">……</div>
<!--th:replace 需要 与 th:fragment 联合使用,一个用于引用模板,一个用于命名模板 例子在第2点-->
工作中的技术总结_Thymeleaf插件_关于th:if 、th:with、th:replace和th:fragment的一些事 _20210825的更多相关文章
- jQuery工作中遇到的几个插件
图片上传插件:uploadify 表单验证插件:formValidator
- 工作中常见的五种技术leader
力不从心型 在工作中有种技术leader,总认为自己是最好的.在方案设计的时候,自己有一种方案,下属有一种方案.leader非要别人听他的.如果两种方案没有优劣之分,比较建议的做法是让真正实施的人按照 ...
- 【转】.Net中通过反射技术的应用----插件程序的开发入门
转自:http://www.cnblogs.com/winloa/archive/2012/03/25/2416355.html .Net中通过反射技术的应用----插件程序的开发入门 再开始之前,先 ...
- Linux 运维工作中的经典应用ansible(批量管理)Docker容器技术(环境的快速搭建)
一 Ansible自动化运维工具 Python 在运维工作中的经典应用 ansible(批量管理操作) .安装ansible(需要bese epel 2种源) wget -O /etc/yum.rep ...
- 工作中经常用到github上优秀、实用、轻量级、无依赖的插件和库
原文收录在我的 GitHub博客 (https://github.com/jawil/blog) ,喜欢的可以关注最新动态,大家一起多交流学习,共同进步,以学习者的身份写博客,记录点滴. 按照格式推荐 ...
- 工作中经常用到 github 上优秀、实用、轻量级、无依赖的插件和库
原文收录在 GitHub博客 ( https://github.com/jawil/blog ) ,喜欢的可以关注最新动态,大家一起多交流学习,共同进步,以学习者的身份写博客,记录点滴. 由于gith ...
- Git-【技术干货】工作中Git的使用实践
Git-[技术干货]工作中Git的使用实践 置顶 2019-09-17 21:02:16 web洋仔 阅读数 11444更多 分类专栏: Git 版权声明:本文为博主原创文章,遵循CC 4.0 B ...
- Android官方技术文档翻译——Gradle 插件用户指南(7)
本文译自Android官方技术文档<Gradle Plugin User Guide>,原文地址:http://tools.android.com/tech-docs/new-build- ...
- 在Gradle中使用jaxb的xjc插件
jaxb,全称为Java Architecture for Xml Binding,是一种将java对象与xml建立起映射的技术.其主要提供两个功能,一是将java对象映射为xml,二是将xml映射为 ...
- 收集一些工作中常用的经典SQL语句
作为一枚程序员来说和数据库打交道是不可避免的,现收集一下工作中常用的SQL语句,希望能给大家带来一些帮助,当然不全面,欢迎补充! 1.执行插入语句,获取自动生成的递增的ID值 INSERT INTO ...
随机推荐
- Apache DolphinScheduler 社区5月月报更新!
各位热爱 DolphinScheduler 的小伙伴们,社区5月份月报更新啦!这里将记录 DolphinScheduler 社区每月的重要更新,欢迎关注,期待下个月你也登上Merge Star月度榜单 ...
- C#数据结构与算法实战入门指南
前言 在编程领域,数据结构与算法是构建高效.可靠和可扩展软件系统的基石.它们对于提升程序性能.优化资源利用以及解决复杂问题具有至关重要的作用.今天大姚分享一些非常不错的C#数据结构与算法实战教程,希望 ...
- 自己实现一个自动检测网卡状态,并设置ip地址,源码见文章底部
阅读本文前,请先学习下面几篇文章 <搞懂进程组.会话.控制终端关系,才能明白守护进程干嘛的?> <简简单单教你如何用C语言列举当前所有网口!> <Linux下C语言操作网 ...
- zabbix 二次开发(添加menu)
zabbix 二次开发--- 在zabbix菜单栏中增加 CMDB 菜单,该菜单下有个子栏目 CMDB overview,如图: 实现此效果,我们需要修改两个地方:menu.inc.php 和 mai ...
- C# 读取excel数据到datatable
在项目中使用到遇到了需要将excel文件导入到数据库中,在此做个总结记录,防止后面人踩坑. 开发环境:VS2008+Win10 第一种方式:Office.Interop.Excel方式 数据量大时有 ...
- MyBatis日志工厂
目录 日志工厂 标准日志实现 Log4j 使用步骤: 日志工厂 我们在测试SQL的时候,要是能够在控制台输出 SQL 的话,是不是就能够有更快的排错效率? 如果一个 数据库相关的操作出现了问题,我们可 ...
- Round #2022/12/03
问题 B: 约数个数 题目描述 有 \(t\) 次询问,每次给你一个数 \(n\) ,求在 \([1,n]\) 内约数个数最多的数的约数个数. 输入 第一行一个正整数 \(t\) . 之后 \(t\) ...
- Mybatis骚操作-通用查询工具类
老项目大多都有对JDBC进行了封装,可以直接执行SQL的工具类,在做项目升级改造的时候(这里仅指整合mybatis),要么全部调整成dao-xml的形式(会有改动代码多的问题,而且看代码时需要xml和 ...
- TypeScript – Using Disposable
前言 TypeScript v5.2 多了一个新功能叫 Disposable. Dispose 的作用是让 "对象" 离开 "作用域" 后做出一些 " ...
- Yarn 3.0 Plug'n'Play (PnP) 安装和迁移
前言 以前用 npm, 后来 yarn 火了就用 yarn. 后来 yarn 2.0 大改版, Angular 不支持就一直没用. 一直到去年的 Angular 13 才开始支持. 最近又开始写 An ...