我有以下URL處理的REST API的特殊字符
http://context_path/info/abc/def
其被轉換像
http://context_path/info/abc%2Fdef
凡爲我的控制器映射爲:
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
這裏「身份證'包含正斜槓(/)。所以當我打到網址時,我收到400錯誤請求。
我知道可能的解決方案
- 設置tomcat的允許正斜槓。
- 使用URL編碼。使用
@RequestParam
代替@PathVariable
。
但上面的解決方案對我來說是不可能的。
問:是否有任何其他解決方案像(使用正則表達式或更改映射或其他任何東西)的問題? 此外,tomcat如何正確處理其他特殊字符('。',''',':',','),並且控制器被打中,但不是'/'。
嘗試,但不工作:
1) @RequestMapping(value = "/info/{id:.*}", method = RequestMethod.GET)
2) @RequestMapping(value = "/info/{id}/**", method = RequestMethod.GET)
3) @RequestMapping(value = "/info/**", method = RequestMethod.GET)
的可能的複製[匹配「其餘的URL」使用Sp ring 3 RequestMapping Annotation](http://stackoverflow.com/questions/4542489/match-the-rest-of-the-url-using-spring-3-requestmapping-annotation) – user1211
但是爲什麼有一個斜槓在你的ID值? – ScanQR
@TechBreak我知道它錯了。但我正在研究舊的價值觀,我無法修改這些。 – SuhasD