使用无操作标记

如果只想让我们的片段把它目前的标记作为默认值,我们也可以使用无操作标记,把它作为传递给片段的参数。再一次使用common_header的例子:

  1. ...
  2. <head th:replace="base :: common_header(_,~{::link})">
  3. <title>Awesome - Main</title>
  4. <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
  5. <link rel="stylesheet" th:href="@{/themes/smoothness/jquery-ui.css}">
  6. </head>
  7. ...

看👀title参数(common_header片段的第一个参数)设置成了无操作标记 (_), 这使得片段的这个部分没有被执行(title=无操作):

  1. <title th:replace="${title}">The awesome application</title>

所以最后就是:

  1. ...
  2. <head>
  3. <title>The awesome application</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. <link rel="stylesheet" href="/awe/css/bootstrap.min.css">
  9. <link rel="stylesheet" href="/awe/themes/smoothness/jquery-ui.css">
  10. </head>
  11. ...