【问题标题】:Thymeleaf Get Curent request parameterThymeleaf 获取当前请求参数
【发布时间】:2018-01-09 18:09:38
【问题描述】:

我正在使用 Thymeleaf 和 Spring boot 开发一个 Web 应用程序。我正在使用片段和布局;我只需要在标头中打印请求参数即可。

示例:

  • 当我打开 localhost:8080/foo/boo 时,我的标题打印 /foo/boo
  • 当我打开 localhost:8080/foo?size=5 时,我的标题打印 /foo?size=5

Thymeleaf 中是否有任何变量可以得到它?

谢谢

【问题讨论】:

    标签: spring spring-boot thymeleaf


    【解决方案1】:

    查询字符串的路径:

    ${#request.requestURI}
    

    查询字符串:

    ${#request.queryString}
    

    获取特定参数(从查询字符串):

    ${#request.getParameter('size')}
    

    【讨论】:

    • 它也适用于 ${#httpServletRequest.getRequestURI()}
    • 为什么这给了我“在这种情况下禁止访问请求参数”:/ <a th:if="${NOT param.isEmpty()}" th:href="@{${#request.requestURI} + ${#request.queryString} + '&sort=subject'}" th:text="#{tsubject}"></a>
    猜你喜欢
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 2016-03-27
    • 2013-08-22
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2017-04-11
    相关资源
    最近更新 更多