我在用Thymeleaf 模板引擎 http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html使用 Spring Web MVC,在当前 url 的帮助下创建 url 时我陷入困境。有什么方法可以获取 Thymeleaf HTML 文件中的当前内容吗?例如:假设我的浏览器地址栏中当前的网址是:
http://localhost:8080/project/web/category/mobiles
现在我想制作一个像这样的网址http://localhost:8080/project/web/category/mobiles/store/samsung
or
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 的变量,所以我想要一些相同的解决方案。硬编码值不会每次都起作用,因为我有动态类别。
我尝试使用相对网址进行相同的操作,但它对我不起作用。
<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
请看一下,如果我做错了什么,请告诉我。
哦,我找到了解决方案。我错过了{#httpServletRequest.requestURI}
在文档中。
这是对我有用的解决方案:
<a th:href="@{__${#httpServletRequest.requestURI}__/store/__${store.name}__}">Click to More</a>
//Will produce: http://localhost:8080/project/web/category/mobiles/store/samsung
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)