亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將url作為@PathVariable傳遞給spring RestController?

如何將url作為@PathVariable傳遞給spring RestController?

月關寶盒 2022-06-15 16:59:06
我想將 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 中有斜杠,因此無法運行。
查看完整描述

2 回答

?
長風秋雁

TA貢獻1757條經驗 獲得超7個贊

用標準代碼替換斜杠:%2F.

http://localhost:8080/app/controller/redirectionTest/1234/http%3A%2F%2Flocalhost%3A3000%2Fmain

我已將冒號替換為%3A以防萬一您對此也有疑問


查看完整回答
反對 回復 2022-06-15
?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

你可以試試這個


@RequestMapping(value = { "/mapping/{param1}" }, method = { RequestMethod.GET})

public void mapping(HttpServletResponse response, @PathVariable("param1") String param1, @RequestParam(required = true, value = "redirectLink") String redirectLink) throws IOException {

    // code i wanna run

    response.sendRedirect(redirectLink);

}

現在,訪問http://localhost:8080/app/controller/redirectionTest/1234?redirectLink=http://localhost:3000/main


查看完整回答
反對 回復 2022-06-15
  • 2 回答
  • 0 關注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號