码迷,mamicode.com
首页 > 编程语言 > 详细

springboot下载文件

时间:2018-12-06 14:24:03      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:throw   NPU   http   temp   path   data   ade   row   encode   

例子

/**
 * 下载假期模板
 */
@ResponseBody
@RequestMapping(value = "/downloadDolidayTemplate.do")
public ResponseEntity downloadDolidayTemplate(Model model, HttpServletRequest request) throws Exception {
    String path = this.getClass().getResource("/").getPath();
    FileInputStream fis = new FileInputStream(path + "conf/template/holidayTemlate.xls");
    byte[] data = new byte[fis.available()];
    fis.read(data);
    HttpHeaders he = new HttpHeaders();
    he.setContentType(MediaType.valueOf("application/x-msdownload"));
    he.set("content-disposition","attachment;filename="+URLEncoder.encode("模板.xls", "UTF-8"));
    return new ResponseEntity<>(data, he, HttpStatus.OK);
}

springboot下载文件

标签:throw   NPU   http   temp   path   data   ade   row   encode   

原文地址:https://www.cnblogs.com/sky-chen/p/10075767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!