fix:导出为页面下载

This commit is contained in:
litianxiang
2026-02-04 14:45:11 +08:00
parent d63b4b4e63
commit d1123aedcc

View File

@@ -11,6 +11,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -165,10 +166,13 @@ public class GlobalAwardController {
@GetMapping("/contestants/export") @GetMapping("/contestants/export")
@ApiOperation(value = "导出参赛者列表为Excel", notes = "导出所有参赛者信息为xlsx并触发下载") @ApiOperation(value = "导出参赛者列表为Excel", notes = "导出所有参赛者信息为xlsx并触发下载")
public Response<Void> exportContestants() throws Exception { public void exportContestants(HttpServletResponse response) throws Exception {
// 将文件保存到服务端本地目录uploadDir/exports不返回文件内容给客户端 byte[] data = globalAwardService.exportContestants();
globalAwardService.saveContestantsToLocal(); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return Response.success(); response.setHeader("Content-Disposition", "attachment; filename=\"contestants.xlsx\"");
response.setContentLength(data.length);
response.getOutputStream().write(data);
response.getOutputStream().flush();
} }
} }