spring mvc通过路径匹配使用@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/wahaha13168/article/details/81211002