【问题标题】:Thymeleaf get current url without base urlThymeleaf 获取没有基本 url 的当前 url
【发布时间】:2017-10-02 13:00:49
【问题描述】:

在 thymeleaf 中有没有办法在基本 url 之后获取当前 url 的部分并将其用作字符串,例如在th:text 中?

示例:http://www.example.com/payment-page/pay 我想要/payment-page/paypayment-page/pay 部分。谢谢。

【问题讨论】:

  • 我会尝试使用 {#httpServletRequest.requestURI} 来获取完整的 URL,然后实现一个简单的函数来从字符串中删除基本 URL。根据您的要求,您也可以在服务器端执行此操作,并将相对 URL 作为字符串变量传递给您的视图。

标签: java spring url thymeleaf


【解决方案1】:

你可以用这个:

<span th:with="url=${#httpServletRequest.requestURI}"/>
<span th:text="${url}"></span> 

示例输出支付页面/支付此网址http://www.example.com/payment-page/pay

【讨论】:

    猜你喜欢
    • 2012-08-28
    • 1970-01-01
    • 2022-07-10
    • 1970-01-01
    • 2016-03-27
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    相关资源
    最近更新 更多