Java Thymeleaf获取当前url而不包含基本url

Java Thymeleaf获取当前url而不包含基本url,java,spring,url,thymeleaf,Java,Spring,Url,Thymeleaf,在thymeleaf中有没有一种方法可以获取当前url在基本url之后的部分,并将其用作字符串,例如在th:text中 示例:http://www.example.com/payment-page/pay我想要/payment page/pay或payment page/pay部分。谢谢。您可以使用: <span th:with="url=${#httpServletRequest.requestURI}"/> <span th:text="${url}"></sp

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

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

您可以使用:

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

examle output payment page/pay for this url。

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