一.删除模板片段使用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标准表达式,只要允许它返回一个字符串值(alltagbodyall-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,因此没有删除会被执行。

最新文章

  1. js动画之平抛运动
  2. 2016年11月3日 星期四 --出埃及记 Exodus 19:19
  3. ubuntu12.04_命令
  4. KindEditor得不到textarea值的解决方法----摘至天涯
  5. ASCII,Unicode和UTF-8字符编码
  6. cdecl、pascal、stdcall、fastcall
  7. Wpf ScrollViewer with WrapPanel 使用鼠标滚轮水平滚动内容
  8. 站长VS微商 你选择哪个?
  9. 谷歌开源图片压缩算法Guetzli实测体验报告
  10. cnpack热键
  11. Proxy和Reflect
  12. python学习日记(初识递归与算法)
  13. JDK1.7和JDK1.8对于异常的支持
  14. Windows下安装及使用NVM
  15. PAT B1005 继续(3n+1)猜想 (25 分)
  16. 常用RAID级别的介绍
  17. 【Android API】Android 4.1 API官方文档详解
  18. MySQL--Workbench表及表种数据导出
  19. AngularJs 与服务器通信 $http, $q, $resource
  20. java使用jacob将office文档转换为PDF格式

热门文章

  1. 替代Eval的两种方式
  2. decode-string(挺麻烦的)
  3. hdu 1257 最少拦截系统(简单贪心)
  4. POJ3485 区间问题
  5. asp.net正则表达式过滤标签和数据提取
  6. I.MX6 Android U-blox miniPCI 4G porting
  7. nginx - ssl 配置 - globelsign ssl
  8. Python cookbook - 读书笔记
  9. 基于ffmpeg的简单音视频编解码的例子
  10. 当ASP.NET MVC模型验证遇上CKEditor