1. 程式人生 > >SpringBoot下載檔案

SpringBoot下載檔案

            String templateFile = "template.xls";
            Resource resource = new ClassPathResource(templateFile);
            response.setContentType("application/force-download");
            response.addHeader("Content-Disposition",
                    "attachment;fileName=" + templateFile);
            IOUtils.copy
(resource.getInputStream(),response.getOutputStream()); response.flushBuffer();