spring-boot - 春季启动 2.2.5。如何在 Spring Filter 中检索 PathVariable 参数
问题描述
我想解决的问题。我需要将特定逻辑应用于 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--
推荐阅读
- scala - 如何在现有的 SBT scala 项目中互操作 kotlin 代码
- google-cloud-platform - 从 GCP Firestore 导出文档所需的最低权限
- sql - SQL如何从两列中提取不同的数据
- gitlab - 从访问令牌中获取 Gitlab 用户
- pandas - 新手问题:为什么这个索引有效?
- c# - NSubstitute.Exceptions.ReceivedCallsException:预计在单元测试时会收到调用匹配错误
- git - 为什么 git checkout 没有改变但触及文件?
- qt - 通过选择表格内容打开新窗口的运行时错误
- bash - 在 Jenkins 中启动 Docker pull 命令失败
- vim - Vim Ack, Ag:在您正在编辑的文件目录中搜索