mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
fix: 课程导出问题修正
继续尝试修正文件名错误的问题
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user