springboot下载文件
例子
/**
* 下载假期模板
*/
@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);
}
如果,您希望更容易地发现我的新博客,不妨点击一下【关注我】。
我的写作热情也离不开您的肯定支持,感谢您的阅读,我是【老梁】!