@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);
}
}
【SpringMVC】下载功能
最新推荐文章于 2023-11-27 08:48:21 发布