关于springmvc中使用@PathVariable时文件扩展名("."后面字符)丢失

今天在做一个文件下载功能,因鉴于通过get请求传参获取文件名和文件路径会出现严重漏洞问题,现采用直接以文件路径的方式访问文件下载,url这样的写法@RequestMapping(value = "/content/{fileName}", method = RequestMethod.GET)会导致文件类型丢失。

解决方案:

在@RequestMapping的value中使用SpEL来表示,value中的{fileName}换成{fileName:.+}。

@RequestMapping(value = "/content/{fileName:.+}", method = RequestMethod.GET)


参考:点击打开链接

猜你喜欢

转载自blog.csdn.net/witewater/article/details/79797811