網(wǎng)站首頁 編程語言 正文
解決No converter for XXX with preset Content-Type ‘a(chǎn)pplication/octet-stream;charset=UTF-8‘
作者:Pisces_224 更新時間: 2022-02-27 編程語言如題
我在后臺封裝下載excel的接口邏輯時,文件流關(guān)閉后響應(yīng)返回success,但是后臺報錯
原因就是我系統(tǒng)整體封裝的響應(yīng)邏輯,所以我在下載文件后也返回了成功和失敗的邏輯。但是并不支持。
try {
List<ExportExcelData> excelDataList = getData(wo_id); // 獲取表體數(shù)據(jù)
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//設(shè)置頭居中
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//內(nèi)容策略
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//設(shè)置 水平居中
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
// 這里URLEncoder.encode可以防止中文亂碼 當(dāng)然和easyexcel沒有關(guān)系
String fileName = URLEncoder.encode(work_order+"報表導(dǎo)出測試", "UTF-8").replaceAll("\\+", "%20");
// response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
response.addHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
response.addHeader("Access-Control-Expose-Headers", "Content-disposition");
// 合并策略
Map<String, List<RowRangeDto>> srategyMap = ExcelUtil.addMergeStrategy(excelDataList);
// 這里需要設(shè)置不關(guān)閉流;
EasyExcel.write(response.getOutputStream(), ExportExcelData.class).autoCloseStream(Boolean.FALSE)
// 注冊合并策略
.registerWriteHandler(new BizMergeStrategy(srategyMap))
.registerWriteHandler(ExcelUtil.CellStyleStrategy())
.sheet("ckd出貨信息表")
.doWrite(excelDataList);
return "文件下載成功"; // 改為void,不反回
} catch (Exception e) {
// 重置response
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
logger.error(e.getMessage());
e.printStackTrace();
return "文件下載失敗"; // 改為void,不反回
}
一個解決辦法是并不返回提示,或者返回null即可避免此類報錯。
但是很遺憾,如果我非要想返回 成功或失敗提示,目前還沒有辦法。
原文鏈接:https://blog.csdn.net/qq_36256590/article/details/122256170
相關(guān)推薦
- 2022-07-30 一文掌握Python正則表達(dá)式_python
- 2022-05-10 console.log() 與 console.dir() 的區(qū)別:
- 2022-07-18 Nacos + OpenFeign 的使用方式
- 2023-11-17 Python中調(diào)用Linux命令并獲取其返回值
- 2022-06-18 C#如何在窗體程序中操作數(shù)據(jù)庫數(shù)據(jù)_C#教程
- 2023-03-21 redis哨兵模式說明與搭建詳解_Redis
- 2022-04-25 Oracle導(dǎo)出導(dǎo)入表結(jié)構(gòu)操作實戰(zhàn)記錄_oracle
- 2022-09-19 Python?argparse?解析命令行參數(shù)模塊詳情_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支