【发布时间】:2017-06-14 16:59:45
【问题描述】:
我尝试通过休息服务启用目录浏览。它的定义是这样的:
@RequestMapping(path="ls/{path:.+}", method = RequestMethod.GET)
public List<String> getDirectoryListing(@PathVariable("path") String path) throws IOException {
// ...
}
但是,如果我使用类似目录的定义,PathVariable {path:.+} 会带来问题。例如,
$ curl http://localhost:8080/fileRepo/ls/dir/subdir
\___ ___/
V
{path:.+}
会导致
{
"timestamp":1485690489272,
"status":404,"error":"Not Found",
"message":"No message available",
"path":"/dataset/ls/processed/dir1/subdir"
}
并在控制台上显示调试消息
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?
【问题讨论】:
-
您只能使用
@RequestParam传递包含/的URL,但不能使用@PathVariable
标签: spring spring-restcontroller