zoukankan      html  css  js  c++  java
  • 下载的模板, 没有之一

        @PostMapping(value = "/template")
        @ApiOperation("xxxxxx")
        public void xxxxxxxxDownload(
                HttpServletResponse response
        ) throws Exception {
            try {
                Resource res = new ClassPathResource(xxxxxxxxx);
                try (BufferedInputStream fis = new BufferedInputStream(res.getInputStream())) {
    
                    int offset = 0;
                    int bytesRead = 0;
                    byte[] data = new byte[fis.available()];
                    while ((bytesRead = fis.read(data, offset, data.length - offset))
                            != -1) {
                        offset += bytesRead;
                        if (offset >= data.length) {
                            break;
                        }
                    }
                    //String str = new String(data, 0, offset, "UTF-8");
                    response.setHeader("Content-Disposition", "attachment; filename=" + res.getFilename());
                    response.setHeader("Access-Control-Allow-Origin", "*");
                    //response.setContentType("application/vnd.ms-read; charset=utf-8");
                    response.setContentType("application/octet-stream");
                    try (OutputStream outStream = new BufferedOutputStream(response.getOutputStream())) {
                        outStream.write(data);
                        outStream.flush();
                    }
                }
            } catch (Exception e) {
                logger.error("xxxxxx" + e.getMessage(), e);
                throw e;
            }
        }
  • 相关阅读:
    Vue常见问题总结
    vue学习记录
    内卷
    at least once 和 at most once 问题
    IO学习笔记(全)
    IO学习笔记7
    IO学习笔记6
    IO学习笔记5
    IO学习笔记4
    IO学习笔记3
  • 原文地址:https://www.cnblogs.com/tekikesyo/p/10711496.html
Copyright © 2011-2022 走看看