在Thymeleaf中链接绝对URL时,th:href和href之间的区别 [英] Difference between th:href and href when linking absolute URLs in Thymeleaf

查看:423
本文介绍了在Thymeleaf中链接绝对URL时,th:href和href之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就在Thymeleaf的开头文档有关标准url语法的信息例子,但是它们之间的区别却没有说:

Right at the beginning of Thymeleaf documentation about standard url syntax there are two examples, but there is nothing said about the difference between them:

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

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

两者之间有区别吗?如果没有,第一个的用途是什么?

Is there a difference between the two? If no, what is the use of the first one?

推荐答案

在这种情况下,没有区别.

In that specific case, there is no difference.

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

将完全产生

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

仅此而已,因为这些部分列出了URL表达式可使用的不同类型的URL(绝对,上下文相关,服务器相关和协议相关).话虽这么说,但您可能会使用它是有原因的...例如,在绝对URL中包含一个ID.像这样:

It's only there to because those sections are listing the different types of urls that url expressions work with (absolute, context relative, server relative and protocol relative). That being said, there are reasons you might use it... such as including an id in an absolute url. Something like:

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

这篇关于在Thymeleaf中链接绝对URL时,th:href和href之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆