@RequestMapping(value="/downloadFile",method=RequestMethodPost)
public void downloaodFile(HttpServletRequest request,HttpServletResponse response,@RequestBody FilePathInfo info){
String downloadPath="";
String fileName="";
byte[] fileByte=null;
fileByte=downloadUtil.download(downloadPath);
response.addHeader("Content-Disposition","attachment;filename="+fileName);
response.setContentType("application/octet-stream");
BufferedOutputStream outputStream=new BufferedOutputStream(response.getOutputStream);
outputStream.write(fileByte);
outputStream.flush();
outputStream.close();
}
使用response存储文件流进行页面文件下载
使用下载工具方法实现文件下载
最新推荐文章于 2024-03-22 08:17:54 发布
该代码片段展示了如何在Spring MVC中实现文件下载。通过`@RequestMapping`注解处理POST请求,`downloadUtil.download()`方法获取文件内容,然后设置响应头以提供附件下载,并以特定的文件名和类型输出到客户端。
1893

被折叠的 条评论
为什么被折叠?



