Springboot中设置response直接下载文件

Springboot中设置response直接下载⽂件
dv观察
河北科技师范学院学报需求: 前台点击链接,浏览器直接下载。
1. 后台代码
/**
* 下载⽂件缢死
*
* @param response ⽂件流
* @throws Exception        流异常
*/
@ApiModelProperty(value = "下载⽂件")
@GetMapping("downFile")
public void downFile(HttpServletResponse response) throws Exception {
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; fileName=" + FullFileName());
普查与抽样调查
as100File file = new File("D:\\file\\1.jpg");
byte[] bytes = ByteArray(file);
out.write(bytes);
out.close();
}
2.前台代码
<a href="127.0.0.1:8080/apis/file/downFile" rel="nofollow">下载⽂件</a>
3.整理
东方影都2003
response在头部设置 "Content-Disposition" 为 "attachment; fileName= xxx" , xxx为⽂件名称,带后缀的⽂件名称,设置之后,⽂件下载的名称就直接是设置的名称;

本文发布于:2024-09-24 01:23:44,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/23939.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:名称   前台   设置   河北   学报
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议