首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为特定的@RequestMapping启用greedy @PathVariable?

如何为特定的@RequestMapping启用greedy @PathVariable?
EN

Stack Overflow用户
提问于 2017-01-29 19:57:23
回答 1查看 388关注 0票数 1

我尝试通过rest服务启用目录浏览。它的定义如下:

代码语言:javascript
复制
@RequestMapping(path="ls/{path:.+}", method = RequestMethod.GET)
public List<String> getDirectoryListing(@PathVariable("path") String path) throws IOException {
  // ...
}

但是,如果我使用类似目录的定义,PathVariable {path:.+}会带来问题。例如,

代码语言:javascript
复制
$ curl http://localhost:8080/fileRepo/ls/dir/subdir
                                         \___ ___/
                                             V 
                                          {path:.+} 

将导致

代码语言:javascript
复制
{
 "timestamp":1485690489272,
 "status":404,"error":"Not Found",
 "message":"No message available",
 "path":"/dataset/ls/processed/dir1/subdir"
 }

并将调试消息放在控制台上

代码语言:javascript
复制
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /files/ls/dir1/subdir
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/files/ls/dir1/subdir]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/files/ls/dir1/subdir] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/files/ls/dir1/subdir] are {}

所以。如何告诉RequestMappingHandlerMapping ls/{path:.+}应该全部解析为getDirectoryListing

EN

回答 1

Stack Overflow用户

发布于 2017-01-29 21:28:39

如果在path变量中发送dir/subdir,则需要转义path变量中的"/“字符。您需要在请求处理程序级别对url的path变量部分进行编码,并对进行解码。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41920623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档