我有以下URL:
http://context_path/info/abc/def
这会被转换为
http://context_path/info/abc%2Fdef
我的控制器映射如下:
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
这里的 'id' 包含斜线 (/)。因此,当我访问URL时,会出现 400 Bad Request 错误。
我知道可能的解决方案:
- 设置tomcat允许斜线。
- 使用URL编码。
- 使用
@RequestParam
而不是@PathVariable
。
但以上解决方案对我来说都不可行。
Q. 是否有其他解决方案(如使用正则表达式或更改映射或其他任何方法)来解决问题? 此外,Tomcat如何正确处理其他特殊字符('.','''',':',','),使控制器得到响应,但'/'却无法得到响应。
已尝试但未能解决问题:
1) @RequestMapping(value = "/info/{id:.*}", method = RequestMethod.GET)
2) @RequestMapping(value = "/info/{id}/**", method = RequestMethod.GET)
3) @RequestMapping(value = "/info/**", method = RequestMethod.GET)