服务器不生产文件,客户端直接下载

    技术2026-10-01  3

    @RequestMapping("/downloadl") @ApiOperation(value = "下载模版", notes = "下载模版", produces = "application/json; charset=utf-8") public ResponseEntity<byte[]> downTemplate(HttpServletResponse response, HttpServletRequest request, String excelName, String fileName) throws IOException { HttpHeaders headers = new HttpHeaders(); fileName="模板"; headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, "utf-8") + ".xlsx"); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM) StringBuffer pathSb = new StringBuffer(ResourceUtils.CLASSPATH_URL_PREFIX); pathSb.append("template"); pathSb.append(File.separator).append(fileName).append(".xlsx"); File file = ResourceUtils.getFile(pathSb.toString()); InputStream is=new FileInputStream(file); byte[] byt = new byte[is.available()]; is.read(byt) return new ResponseEntity<>(byt, headers, HttpStatus.CREATED); }
    Processed: 0.010, SQL: 9