测试方式如下
- 直接保存文件到本地 - 不乱码
- postman测试接口,send and download - 中文乱码,数据正常
- swagger测试接口,文件全部乱码:锟斤拷唷?锟?;锟斤拷
### 代码历史如下
HttpServletResponse res = null; res = getResponse(); res.reset(); // res.setContentType("octets/stream"); res.setContentType("application/octet-stream; charset=utf-8"); // res.setContentType("application/vnd.ms-excel;charset=utf-8"); // res.setContentType("application/msexcel"); String fileName = sensorShowNo + "_eff_data_export"; // res.setCharacterEncoding("UTF-8"); // res.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1") + ".xls"); // res.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls","UTF-8")); res.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gb2312"), "ISO8859-1") + ".xls"); // res.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gbk"), "ISO8859-1") + ".xls"); OutputStream out = response.getOutputStream(); Workbook workbook = sensorDataService.exportEff(sensor.getSensorNo(), sensorSearch.getStartTime(), sensorSearch.getEndTime()); workbook.write(res.getOutputStream()); out.flush(); out.close();