【问题标题】:Spring Boot 2.2.5. How to retrieve a PathVariable parameter inside a Spring Filter春季启动 2.2.5。如何在 Spring Filter 中检索 PathVariable 参数
【发布时间】:2020-05-27 07:49:42
【问题描述】:

我想解决的问题。 我需要将特定逻辑应用于 url 属于特定子路径的所有 restful 端点:比如说“/api/employee/{id}”。这意味着以该路径开头的所有链接都应应用基于员工 ID 的逻辑,我试图直接在 Spring Boot 过滤器中应用该逻辑,以避免将逻辑传播到任何地方。

我面临的问题。 我可以从 ServletRequest 中获取查询参数,但过滤器中没有 PathVariables。

知道如何解析吗?

将不胜感激:)

【问题讨论】:

    标签: spring-boot filter restful-url path-variables


    【解决方案1】:

    PathVariables 只是 URI。不能拨打getRequestURI()

    来自文档:

    java.lang.String getRequestURI()
    
    Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example:
    
    First line of HTTP request  Returned Value
    
    POST /some/path.html HTTP/1.1       /some/path.html
    
    GET http://foo.bar/a.html HTTP/1.0      /a.html
    
    HEAD /xyz?a=b HTTP/1.1      /xyz
    

    https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html#getRequestURI--

    【讨论】:

    猜你喜欢
    • 2021-05-06
    • 2020-08-05
    • 2019-02-28
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 2015-04-18
    • 2017-06-24
    相关资源
    最近更新 更多