1.controller层
@GetMapping(ReviewUrls.API_DOWNLOAD_REVIEW_RESULT)public Response<Void> downloadReviewResult(HttpServletResponse response) {resultService.downloadReviewResult(response);return Response.ok();}
2.service层
public void downloadReviewResult(HttpServletResponse response) {String filePath = "test.xslx";try (FileInputStream inputStream = new FileInputStream(filePath);ServletOutputStream outputStream = response.getOutputStream();) {response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));byte[] buffer = new byte[1024];int bytesRead;while ((bytesRead = inputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, bytesRead);}outputStream.flush();} catch (Exception e) {throw new RuntimeException("下载结果失败");}}