使用空片段

一种特殊的分段表达式——空片段(~{}),可以用于不🈯️定标记。使用之前的例子:

  1. <head th:replace="base :: common_header(~{::title},~{})">
  2. <title>Awesome - Main</title>
  3. </head>
  4. ...

注意片段的第二个参数(links)设置成了🈳️片段。因此,<th:block th:replace="${links}" />的地方什么也没有:

  1. ...
  2. <head>
  3. <title>Awesome - Main</title>
  4. <!-- Common styles and scripts -->
  5. <link rel="stylesheet" type="text/css" media="all" href="/awe/css/awesomeapp.css">
  6. <link rel="shortcut icon" href="/awe/images/favicon.ico">
  7. <script type="text/javascript" src="/awe/sh/scripts/codebase.js"></script>
  8. </head>
  9. ...