Commit 6d93ea2c7f13152402d1584be6c5433c1605bc1c
1 parent
da8666d0
新加了一个导出模板的方法
Showing
1 changed file
with
25 additions
and
0 deletions
src/main/java/com/bsth/controller/DownloadController.java
| ... | ... | @@ -100,4 +100,29 @@ public class DownloadController |
| 100 | 100 | os.close(); |
| 101 | 101 | file.delete(); |
| 102 | 102 | } |
| 103 | + | |
| 104 | + | |
| 105 | + @RequestMapping("downloadModel") | |
| 106 | + public void downloadModel(HttpServletResponse response,String fileName) | |
| 107 | + throws IOException { | |
| 108 | +// String fileNames=URLDecoder.decode(fileName,"UTF-8"); | |
| 109 | + fileName =fileName + ".xls"; | |
| 110 | + String moudelPath = this.getClass().getResource("/").getPath()+ "static/pages/forms/export/"+fileName; | |
| 111 | + File file = new File(moudelPath);// path是根据日志路径和文件名拼接出来的 | |
| 112 | +// String filename = file.getName();// 获取日志文件名称 | |
| 113 | + InputStream fis = new BufferedInputStream(new FileInputStream(moudelPath)); | |
| 114 | + byte[] buffer = new byte[fis.available()]; | |
| 115 | + fis.read(buffer); | |
| 116 | + fis.close(); | |
| 117 | + response.reset(); | |
| 118 | + response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.replaceAll(" ", "").getBytes("utf-8"),"iso8859-1")); | |
| 119 | + response.addHeader("Content-Length", "" + file.length()); | |
| 120 | + OutputStream os = new BufferedOutputStream(response.getOutputStream()); | |
| 121 | + response.setContentType("application/octet-stream"); | |
| 122 | + os.write(buffer);// 输出文件 | |
| 123 | + os.flush(); | |
| 124 | + os.close(); | |
| 125 | + } | |
| 126 | + | |
| 127 | + | |
| 103 | 128 | } | ... | ... |