我有以下代码,但第二种方法存在的唯一原因是因为第一种方法不匹配我正在服务的静态文件的子目录。
@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 );
}