不使用th:fragment引用片段

多亏了强大的Markup Selectors,我们能够在不使用th:fragment属性的情况下,包含片段。甚至可以是来自不同应用的标记代码,没有一丁点Thymeleaf的知识:

  1. ...
  2. <div id="copy-section">
  3. &copy; 2011 The Good Thymes Virtual Grocery
  4. </div>
  5. ...

我们可以通过id属性简单地引用上面的片段,类似于CSS选择器:

  1. <body>
  2. ...
  3. <div th:insert="~{footer :: #copy-section}"></div>
  4. </body>