1 |
|
默认配置时,不同的 URL ,获取到的 filename 为:
/api/file/foo
,filename 为 foo/api/file/foo.pdf
,filename 为 foo/api/file/foo.pdf.png
,filename 为 foo.pdf/api/file/foo.pdf.png.doc
,filename 为 foo.pdf.png
最后一个 .
被截断了,解决这个问题有 2 中方法:
使用正则表达式进行路径匹配,映射为:
@GetMapping("/api/file/{filename:.+}")
- 缺点:每个路径的映射都要写一遍,不方便
- 优点:缺点也是优点,只影响需要的路径
配置
annotation-driven
,映射为:@GetMapping("/api/file/{filename}")
- 优点:只需要配置一次,整个应用都生效,方便
- 缺点:优点也是缺点,影响了整个系统,不过还没有发现对整个系统有什么副作用
1
2
3
4<mvc:annotation-driven>
<mvc:path-matching registered-suffixes-only="true"/>
...
</mvc:annotation-driven>