【SpringMVC】下载功能

来源:互联网 发布:encore软件 编辑:程序博客网 时间:2024/05/22 13:12
@RequestMapping("/download")public void download(String sfId, HttpServletRequest request, HttpServletResponse response){try {if (!StringUtil.isNullOrEmpty(sfId)) {SampleDocument sampleDocument = sampleDocumentService.findBySfId(sfId);String title = sampleDocument.getTitle();Blob content = sampleDocument.getContent();if (content != null) {byte[] subByte =  content.getBytes(1,(int)content.length());response.setHeader("Content-lenth", Integer.toString(subByte.length));// 文件名称转码response.setHeader("Content-disposition","attachment;filename="+ new String(title.getBytes("GBK"),"ISO-8859-1"));response.getOutputStream().write(subByte);response.setStatus(HttpStatus.OK.value());}}} catch (Exception e) {log.error("download error message:" + e.getMessage(), e);}}

0 0
原创粉丝点击