工作中的技术总结_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的更多相关文章

  1. jQuery工作中遇到的几个插件

    图片上传插件:uploadify 表单验证插件:formValidator

  2. 工作中常见的五种技术leader

    力不从心型 在工作中有种技术leader,总认为自己是最好的.在方案设计的时候,自己有一种方案,下属有一种方案.leader非要别人听他的.如果两种方案没有优劣之分,比较建议的做法是让真正实施的人按照 ...

  3. 【转】.Net中通过反射技术的应用----插件程序的开发入门

    转自:http://www.cnblogs.com/winloa/archive/2012/03/25/2416355.html .Net中通过反射技术的应用----插件程序的开发入门 再开始之前,先 ...

  4. Linux 运维工作中的经典应用ansible(批量管理)Docker容器技术(环境的快速搭建)

    一 Ansible自动化运维工具 Python 在运维工作中的经典应用 ansible(批量管理操作) .安装ansible(需要bese epel 2种源) wget -O /etc/yum.rep ...

  5. 工作中经常用到github上优秀、实用、轻量级、无依赖的插件和库

    原文收录在我的 GitHub博客 (https://github.com/jawil/blog) ,喜欢的可以关注最新动态,大家一起多交流学习,共同进步,以学习者的身份写博客,记录点滴. 按照格式推荐 ...

  6. 工作中经常用到 github 上优秀、实用、轻量级、无依赖的插件和库

    原文收录在 GitHub博客 ( https://github.com/jawil/blog ) ,喜欢的可以关注最新动态,大家一起多交流学习,共同进步,以学习者的身份写博客,记录点滴. 由于gith ...

  7. Git-【技术干货】工作中Git的使用实践

    Git-[技术干货]工作中Git的使用实践 置顶 2019-09-17 21:02:16 web洋仔 阅读数 11444更多 分类专栏: Git   版权声明:本文为博主原创文章,遵循CC 4.0 B ...

  8. Android官方技术文档翻译——Gradle 插件用户指南(7)

    本文译自Android官方技术文档<Gradle Plugin User Guide>,原文地址:http://tools.android.com/tech-docs/new-build- ...

  9. 在Gradle中使用jaxb的xjc插件

    jaxb,全称为Java Architecture for Xml Binding,是一种将java对象与xml建立起映射的技术.其主要提供两个功能,一是将java对象映射为xml,二是将xml映射为 ...

  10. 收集一些工作中常用的经典SQL语句

    作为一枚程序员来说和数据库打交道是不可避免的,现收集一下工作中常用的SQL语句,希望能给大家带来一些帮助,当然不全面,欢迎补充! 1.执行插入语句,获取自动生成的递增的ID值 INSERT INTO ...

随机推荐

  1. 瑞芯微|如何让拥有双网口的Linux设备实现数据包转发?【超实用】

    本文主要讲解如何,解决基于3568实现双网口互通问题. 一.组网 如下图所示: rk3568自带2个千兆以太口,对应网卡名称为:eth0.eth1 pc1和pc2分别连接这2个网口 pc1与eth0连 ...

  2. Docker简单使用总结

    写在前面 最近在部署前后端分离的SpringBoot项目,发现使用Docker技术很方便,特此记录一下Docker常用命令 1.常用网站 Docker docs :https://docs.docke ...

  3. 电商API接口应该如何使用?

    从定义上看,API接口是指预先定义的一组规则和协议,允许不同的软件应用之间相互通信和交换数据. 目前,市场中电商行业用到API接口的场景较多,电商API接口则是专门针对电子商务应用场景所提供的API, ...

  4. ChatGPT学习之旅 (10) 系统全球化小助手

    大家好,我是Edison. 上一篇我们写了一个运维小助手的prompt,它帮我们写一些我们开发者不太愿意做的一些运维小任务.这一篇,给大家分享下我在日常的系统开发中遇到的多语言/全球化的任务中是如何通 ...

  5. Python自动复制Excel数据:将各行分别重复指定次数

      本文介绍基于Python语言,读取Excel表格文件数据,并将其中符合我们特定要求的那一行加以复制指定的次数,而不符合要求的那一行则不复制:并将所得结果保存为新的Excel表格文件的方法.   这 ...

  6. K8s文件解析 涉及 SLS、MSE、NAS存储卷等

    k8s.yml模板 涉及配置: 1. 存储卷(NAS) 2. SLS设定(阿里云日志采集系统) 3. MSE配置(阿里云版nacos) 4. 配置应用参数(包括路径,布尔类型数据等) apiVersi ...

  7. SpringMVC:文件上传和下载

    文件下载 ResponseEntity用于控制器方法的返回值类型,该控制器方法的返回值就是响应到浏览器的响应报文 使用ResponseEntity实现下载文件的功能 @RequestMapping(& ...

  8. ​Spring:IOC(2)

    接前文:Spring:IOC 目录 依赖注入之setter注入 依赖注入之构造器注入 特殊值处理 字面量赋值 null值 xml实体 CDATA节 为类类型属性赋值 为数组类型属性赋值 修改Stude ...

  9. HEDGE: 通过特征交互检测生成文本分类的层次解释《Generating Hierarchical Explanations on Text Classification via Feature Interaction Detection》(LIME算法、神经网络预测的分层解释CD和ACD、Shapley Value夏普利值、Leave-One-Out留一法、HEDGE)

    先来吐个槽:啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊,为什么我的导师又嫌我PPT做的很烂,( Ĭ ^ Ĭ ) 论文:Generating Hierarchical Explanations on Text Cl ...

  10. Linux下Shell脚本实现统一管理服务启停重启

    公司今年开始了大批量的裁员,人心惶惶,所以强迫自己学习点新知识,刚好领导给找了个事情,让写个脚本实现一键启停Linux服务器上的服务,于是开始研究这个怎么搞. 最开始的时候,有点想当然了,觉得一键启停 ...