首页 > 编程语言 > 详细

springboot下载文件

时间:2018-12-06 12:44:19      阅读:136      评论:0      收藏:0      [点我收藏+]

例子

/**
 * 下载假期模板
 */
@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下载文件

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!