package org.bigdata.framework.core.controller; import org.apache.commons.io.FileUtils; import org.bigdata.framework.core.common.OwlCustomConfigs; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import java.io.File; @Controller public class ShowDownLoadController { @RequestMapping(value="download.html") public String toDownloadHtml() { return "/download.html"; } @RequestMapping(value="/downExportOwl",method = RequestMethod.GET) public ResponseEntity<byte[]> downExportXml(String filePath) throws Exception { File file = new File(OwlCustomConfigs.filePath + filePath); String fileName = file.getName(); String downloadFielName = null; ResponseEntity<byte[]> responseEntity = null; try { downloadFielName = new String(fileName.getBytes("GBK"),"iso-8859-1"); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Disposition","attachment;filename="+downloadFielName); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); responseEntity = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.OK); } catch (Exception e) { e.printStackTrace(); } return responseEntity; } }
spring下载文件
最新推荐文章于 2025-02-28 12:12:59 发布