如何使用 Thymeleaf 的显式链接?
How to use explicit links with Thymeleaf?
我想在 Spring+Thymeleaf 网络应用程序中创建并 link 到外部站点,并像这样插入 link:<a th:href="@{https://example.com}">Link</a>
然而,通过单击 link,它会尝试指向内部位置 http://localhost/service/https://example.com
而不是外部网站 https://example.com,就像它应该的那样。
网站只给出错误 "status":500,"error":"Internal Server Error","message":"The request was rejected because the URL was not normalized."
有什么问题以及如何使用 Thymeleaf 制作绝对 links?
如果 link 是一个静态的你可以简单地使用
<a href="https://example.com">Link</a>
如果是动态的,
您可以在模板中使用 <a th:href="${link}">Link</a>
。并在控制器中
return new ModelAndView("page").addObject("link", <link>)
问题在于该应用程序是在其他 Spring+Thymeleaf 项目之上构建的。我 link 工作的唯一方法就是这样。
<a th:text="link" th:onclick="|window.location.href='@{https://example.com}'|"></a>
我知道这不是“真实的”link,无法配置为使用 target="_blank"
左右打开,但它适用于此用例。
我想在 Spring+Thymeleaf 网络应用程序中创建并 link 到外部站点,并像这样插入 link:<a th:href="@{https://example.com}">Link</a>
然而,通过单击 link,它会尝试指向内部位置 http://localhost/service/https://example.com
而不是外部网站 https://example.com,就像它应该的那样。
网站只给出错误 "status":500,"error":"Internal Server Error","message":"The request was rejected because the URL was not normalized."
有什么问题以及如何使用 Thymeleaf 制作绝对 links?
如果 link 是一个静态的你可以简单地使用
<a href="https://example.com">Link</a>
如果是动态的,
您可以在模板中使用 <a th:href="${link}">Link</a>
。并在控制器中
return new ModelAndView("page").addObject("link", <link>)
问题在于该应用程序是在其他 Spring+Thymeleaf 项目之上构建的。我 link 工作的唯一方法就是这样。
<a th:text="link" th:onclick="|window.location.href='@{https://example.com}'|"></a>
我知道这不是“真实的”link,无法配置为使用 target="_blank"
左右打开,但它适用于此用例。