我想解决的问题。我需要对URL属于特定子路径的所有Restful端点应用特定的逻辑:比如说“ / api / employee / {id}”。这意味着所有以此路径开头的链接都应基于雇员ID应用一个逻辑,我正尝试直接在Spring Boot过滤器中应用该逻辑,以避免将逻辑散布到各处。
我面临的问题。我可以从ServletRequest获取查询参数,但是PathVariables在过滤器中不可用。
任何想法如何解析?
非常感谢:)
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--