java - 如何将url作为@PathVariable传递给spring RestController?
问题描述
我想将 URL 放入 GET 请求中,这样我就可以将用户重定向到给定的 URL。
到目前为止,这是我的代码:
@RequestMapping(value = { "/mapping/{param1}/{redirectLink}" }, method = { RequestMethod.GET})
public void mapping(HttpServletResponse response, @PathVariable("param1") String param1, @PathVariable("redirectLink") String redirectLink) throws IOException {
// code i wanna run
response.sendRedirect(backLink);
}
我用来获取的示例 url - http://localhost:8080/app/controller/redirectionTest/1234/http://localhost:3000/main
因此,当我调用 GET 方法时,我想运行一些代码,然后将其重定向到http://localhost:3000/main但 URL 中有斜杠,因此无法运行。
解决方案
用标准代码替换斜杠:%2F
.
http://localhost:8080/app/controller/redirectionTest/1234/http%3A%2F%2Flocalhost%3A3000%2Fmain
我已将冒号替换为%3A
以防万一您对此也有疑问
推荐阅读
- python - Python 类可下标但不可迭代
- git - emacs 不备份 git repo 中的文件
- recursion - Preorder traversal without recursion
- ansible - 可变模块字段
- json - How to create multiple instance of backendAddressPools, frontendports in Application Gateways through ARM template
- javascript - 制作响应式可折叠导航栏。我很难让 Javascript 在点击时工作
- google-sheets - Is there a way to filter a pivot query to remove the blank column
- react-native - 将 react-native 升级到 0.60、将组件复制到新项目或更改 package.json 版本的最佳方法?
- javascript - 二维数组在 JavaScript 中的意外结果
- python - 如何在 Cython 中有一个内存视图列表?