将子目录路径与Spring Web MVC匹配?

时间:2016-07-24 07:02:18

标签: java spring spring-mvc

我有以下代码,但第二种方法存在的唯一原因是因为第一种方法不匹配我正在服务的静态文件的子目录。

@RequestMapping( method = RequestMethod.GET, value = "/{filename:.+}" )
public ResponseEntity<?> getFile( @PathVariable final String filename ) {
    Resource resource = resourceLoader.getResource( root.resolve( filename ).toUri().toString() );
    return ResponseEntity.ok()
            .cacheControl( CacheControl.maxAge( 1, TimeUnit.DAYS ).proxyRevalidate().cachePrivate() )
            .body( resource );
}

@RequestMapping( method = RequestMethod.GET, value = "/{path}/{filename:.+}" )
public ResponseEntity<?> getFile( @PathVariable final String path, @PathVariable  final String filename ) {
    Resource resource = resourceLoader.getResource( root.resolve( path ).resolve( filename ).toUri().toString() );
    return ResponseEntity.ok()
            .cacheControl( CacheControl.maxAge( 1, TimeUnit.DAYS ).proxyRevalidate().cachePrivate() )
            .body( resource );
}

0 个答案:

没有答案