thymeleaf中的th:remove用法
一.删除模板片段使用th:remove属性
th:remove的值如下:
1.all:删除包含标签和所有的孩子。
2.body:不包含标记删除,但删除其所有的孩子。
3.tag:包含标记的删除,但不删除它的孩子。
4.all-but-first:删除所有包含标签的孩子,除了第一个。
5.none:什么也不做。这个值是有用的动态评估。
<table>
<tr>
<th>NAME</th>
<th>PRICE</th>
<th>IN STOCK</th>
<th>COMMENTS</th>
</tr>
<tr th:each="prod : ${prods}" th:class="${prodStat.odd}? 'odd'">
<td th:text="${prod.name}">Onions</td>
<td th:text="${prod.price}">2.41</td>
<td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
<td>
<span th:text="${#lists.size(prod.comments)}">2</span> comment/s
<a href="comments.html"
th:href="@{/product/comments(prodId=${prod.id})}"
th:unless="${#lists.isEmpty(prod.comments)}">view</a>
</td>
</tr>
<tr class="odd" th:remove="all">
<td>Blue Lettuce</td>
<td>9.55</td>
<td>no</td>
<td>
<span>0</span> comment/s
</td>
</tr>
<tr th:remove="all">
<td>Mild Cinnamon</td>
<td>1.99</td>
<td>yes</td>
<td>
<span>3</span> comment/s
<a href="comments.html">view</a>
</td>
</tr>
</table>
结果为:
<table>
<tr>
<th>NAME</th>
<th>PRICE</th>
<th>IN STOCK</th>
<th>COMMENTS</th>
</tr>
<tr>
<td>Fresh Sweet Basil</td>
<td>4.99</td>
<td>yes</td>
<td>
<span>0</span> comment/s
</td>
</tr>
<tr class="odd">
<td>Italian Tomato</td>
<td>1.25</td>
<td>no</td>
<td>
<span>2</span> comment/s
<a href="/gtvg/product/comments?prodId=2">view</a>
</td>
</tr>
<tr>
<td>Yellow Bell Pepper</td>
<td>2.50</td>
<td>yes</td>
<td>
<span>0</span> comment/s
</td>
</tr>
<tr class="odd">
<td>Old Cheddar</td>
<td>18.75</td>
<td>yes</td>
<td>
<span>1</span> comment/s
<a href="/gtvg/product/comments?prodId=4">view</a>
</td>
</tr>
</table>
最后两行<tr>被删除了。
二.th:remove属性可以采取任何Thymeleaf标准表达式,只要允许它返回一个字符串值(all, tag, body, all-but-first or none)。
这意味着删除可能是有条件的:
<a href="/something" th:remove="${condition}? tag : none">Link text not to be removed</a>
th:remove 把null 等同于 none,所以下面和上面的其实是一样的:
<a href="/something" th:remove="${condition}? tag">Link text not to be removed</a>
因此,如果${condition} is 是false,将返回null,因此没有删除会被执行。
thymeleaf中的th:remove用法的更多相关文章
- C++中vector的remove用法
我将从remove的复习开始这个条款,因为remove是STL中最糊涂的算法.误解remove很容易,驱散所有关于remove行为的疑虑——为什么它这么做,它是怎么做的——是很重要的. 这是rem ...
- thymeleaf中的th:each用法
一.th:eath迭代集合用法: <table> <thead> <tr> <th>序号</th> <th>用户名</th ...
- thymeleaf中的条件判断用法
一.简单的条件:“if”和“unless” th:if用法实例: <table> <tr> <th>NAME</th> <th>PRICE& ...
- thymeleaf中的th:with用法
局部变量,th:with能定义局部变量: <div th:with="firstPer=${persons[0]}"> <p> The name of th ...
- thymeleaf中的th:assert用法
th:assert 断言标签 th:assert属性可以指定一个以逗号分隔的表达式对其进行评估并生产适用于每一个评价,如果不抛出异常 <div th:assert="${onevar} ...
- thymeleaf中th:attr用法以及相关的thymeleaf基本表达式
额,有人写的很好,我直接搬了 thymeleaf中th:attr用法 1.写死的单个属性值添加 th:attr="class=btn" 2.写死的多个属性值添加 th:attr=& ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- Linux中yum和apt-get用法及区别
Linux中yum和apt-get用法及区别 一般来说著名的linux系统基本上分两大类: 1.RedHat系列:Redhat.Centos.Fedora等 2.Debian系列:Debi ...
- ASP.NET中application对象的用法(面试题)
ASP.NET中application对象的用法 本文导读:Application对象是HttpApplicationState类的一个实例,Application状态是整个应用程序全局的.Appli ...
随机推荐
- static,this,抽象类,接口和包
1. static 1)静态变量:Java虚拟机为静态变量开辟单独的存储空间,所以所有的对象内部的静态变量在内存中都指向同一个地址,那么不管哪个对象改变这个成员变量,所有对象中该成员变量的值都发生变化 ...
- C++ STL之vector容器的基本操作
注意事项:特别注意任何时候同时使用两个迭代器产生的将会是一个前闭后开的区间(具体见插入和删除的例子)特别注意begin()指向的是vec中的第0个元素,而end是指向最后一个元素的后面一个位置(不是最 ...
- apache启动报错(98)Address already in use: make_sock: could not bind to...
# /etc/init.d/httpd startStarting httpd: (98)Address already in use: make_sock: could not bind to ad ...
- 【Todo】深入理解Javascript系列
真的很好,要看 http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html
- A06_RelativeLayout的属性设置
设有两个控件one和two,以控件one为基准.由于代码比较简单就不贴了,直接上效果图. 一.第一组:将控件two放在控件one的上.下.左.右.开始.结束. android:layout_below ...
- voliecty indexOf的写法
Velocity allows you to use all Java methods available in your objects. So just write as if it was Ja ...
- bzoj3252
简单题,每次取出最长链,然后对于练上每个点x,终点在其子树内的链都要减去a[x] 这显然可以用dfs序+线段树维护 显然每个点只要删一次即可,复杂度是O(nlogn) type node=record ...
- .net项目的svn Global ignore pattern
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__ *.rej *~ #*# .#* .*.swp .DS_S ...
- usaco /the first wave
bzoj1572:贪心.先按时间顺序排序,然后用优先队列,如果时间不矛盾直接插入,否则判断队列中w最小的元素是否替换掉.(没用llWA了一次 #include<cstdio> #inclu ...
- Jqgrid入门-使用模态对话框编辑表格数据(三)
Jqgrid是一个强大的表格插件,它提供了多种方式来编辑数据.这三种方式分别是: Cell Editing——只允许修改某一个单元格内容 Inline Editing——允许在jqGr ...