我尝试通过rest服务启用目录浏览。它的定义如下:
@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
发布于 2017-01-29 21:28:39
如果在path变量中发送dir/subdir,则需要转义path变量中的"/“字符。您需要在请求处理程序级别对url的path变量部分进行编码,并对进行解码。
https://stackoverflow.com/questions/41920623
复制相似问题