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为⽂件名称,带后缀的⽂件名称,设置之后,⽂件下载的名称就直接是设置的名称;