【发布时间】:2017-03-13 22:27:48
【问题描述】:
就在 Thymeleaf documentation 的开头,关于标准 url 语法有两个例子,但没有说明它们之间的区别:
<a th:href="@{http://www.thymeleaf/documentation.html}">
<a href="http://www.thymeleaf/documentation.html">
这两者有区别吗?如果不是,第一个有什么用?
【问题讨论】:
就在 Thymeleaf documentation 的开头,关于标准 url 语法有两个例子,但没有说明它们之间的区别:
<a th:href="@{http://www.thymeleaf/documentation.html}">
<a href="http://www.thymeleaf/documentation.html">
这两者有区别吗?如果不是,第一个有什么用?
【问题讨论】:
在那种特定情况下,没有区别。
<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>
【讨论】: