我需要一个只匹配任何路径级别图像的请求映射器。
例如,它必须匹配;
http://localhost:8080/filename.jpg
http://localhost:8080/figs/filename.jpg
我尝试了正则表达式和非正则表达式;
@RequestMapping(value = "{reg:(?:\\w|\\W)+\\.(?:jpg|bmp|gif|jpeg|png|webp)$}", method = RequestMethod.GET)
但是,它与http://localhost:8080/filename.jpg
匹配,但与http://localhost:8080/figs/filename.jpg
或http://localhost:8080/anypathlevelNtimes/
figs/filename.jpg
不匹配
它如何与所有路径级别匹配,文件扩展名只是图像。
编辑:现在没关系
@RequestMapping(value = {"/**/{extension:(?:\\w|\\W)+\\.(?:jpg|bmp|gif|jpeg|png|webp)$}"}, method = RequestMethod.GET)
答案 0 :(得分:1)
OP提出的解决方案:
@RequestMapping( //
value = {"/**/{extension:(?:\\w|\\W)+\\.(?:jpg|bmp|gif|jpeg|png|webp)$}"}, //
method = RequestMethod.GET //
)
答案 1 :(得分:-1)
@RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}")
public void handle(@PathVariable String version, @PathVariable String extension) {
// ...
}
reference https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html
https://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/util/AntPathMatcher.html