我正在使用Thymeleaf模板引擎与Spring Web MVC,并且在创建带有当前URL的URL时遇到了困难。是否有办法在Thymeleaf HTML文件中获取当前URL?例如:假设我的浏览器地址栏中的当前URL为:
这里我使用了一个名为
请看一下,如果我做错了什么,请告诉我。
http://localhost:8080/project/web/category/mobiles
,现在我想要创建一个URL,如http://localhost:8080/project/web/category/mobiles/store/samsung
或http://localhost:8080/project/web/category/mobiles?min_price=10&max_price=100
。因此,代码将如下所示:<a th:with="currentUrl='http://localhost:8080/project/web/category/mobiles'"
th:href="@{__${currentUrl}__/__${store.name}__}">
Click to More Result
</a>
这里我使用了一个名为
currentUrl
的变量,其中包含硬编码的URL,因此我希望找到一些解决方案。硬编码的值并不总是适用,因为我有动态类别。 我尝试使用相对URL,但对我来说没有起作用。<a th:href="@{/store/__${store.name}__}">Click to More</a>
//will produce: http://localhost:8080/project/web/store/samsung
//I want: http://localhost:8080/project/web/category/mobiles/store/samsung
请看一下,如果我做错了什么,请告诉我。
http://localhost:8080/project
是我的基本 URL,/web/category/{categoryName}
由控制器映射。我尝试了相对路径,但似乎不起作用,我正在使用<a th:href="@{/store/__${store.name}__}>" 点击查看更多</a>
来生成相对 URL。 - Anil Kumar Pandey