【问题标题】:Difference between th:href and href when linking absolute URLs in Thymeleaf在 Thymeleaf 中链接绝对 URL 时 th:href 和 href 之间的区别
【发布时间】:2017-03-13 22:27:48
【问题描述】:

就在 Thymeleaf documentation 的开头,关于标准 url 语法有两个例子,但没有说明它们之间的区别:

<a th:href="@{http://www.thymeleaf/documentation.html}">

<a href="http://www.thymeleaf/documentation.html">

这两者有区别吗?如果不是,第一个有什么用?

【问题讨论】:

    标签: html thymeleaf


    【解决方案1】:

    在那种特定情况下,没有区别。

    <a th:href="@{http://www.thymeleaf/documentation.html}">
    

    会准确生产

    <a href="http://www.thymeleaf/documentation.html">
    

    只是因为这些部分列出了 url 表达式使用的不同类型的 url(绝对的、上下文相关的、服务器相关的和协议相关的)。话虽如此,您可能会使用它的原因......例如在绝对网址中包含一个 id。比如:

    <th:block th:with="id=${42774564}">
      <a th:href="@{https://stackoverflow.com/questions/{id}(id=${id})}">Stack Overflow</a>
    </th:block>
    

    【讨论】:

      猜你喜欢
      • 2018-05-06
      • 2012-08-15
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2016-09-03
      相关资源
      最近更新 更多