fix: 课程导出问题修正

继续尝试修正文件名错误的问题
This commit is contained in:
liu.zixi
2025-11-24 14:05:44 +08:00
parent c5bcf8fa57
commit 6f6fb8e00b

View File

@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -286,7 +287,13 @@ public class CoursePageServiceImpl implements ICoursePageService {
try (OutputStream out = response.getOutputStream()) {
response.setContentType("application/octet-stream");
String fileName = "课程列表.xlsx";
response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
// 对文件名进行 URL 编码(用于 filename*
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()).replaceAll("\\+", "%20");
// 设置 Content-Disposition同时提供 filename 和 filename*
response.setHeader("Content-Disposition",
"attachment; filename=\"" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1) + "\"; filename*=UTF-8''" + encodedFileName);
ExportsExcelSenderUtil.exportDynamic(exportMap, dataList, out, null);
} catch (Exception e) {
throw new AppException("导出课程列表发生异常", e);