上海联通 网站备案,grace6.1 wordpress,.net网站开发实训体会,网站建设维护phpJava IDEA controller导出CSV#xff0c;excel 导出excel/csv#xff0c;亲测可共用一个方法#xff0c;代码逻辑里判断设置不同的表头及contentType#xff1b;导出excel导出csv 优化#xff1a;有数据时才可以导出参考 导出excel/csv#xff0c;亲测可共用一个方法excel 导出excel/csv亲测可共用一个方法代码逻辑里判断设置不同的表头及contentType导出excel导出csv 优化有数据时才可以导出参考 导出excel/csv亲测可共用一个方法代码逻辑里判断设置不同的表头及contentType
导出excel
egxls response.setContentType(application/vnd.ms-excel);response.setHeader(Content-Disposition, attachment;fileName URLEncoder.encode(导出表.xlsx, utf-8));导出csv
egcsv response.setContentType(application/csv);response.setHeader(content-disposition, attachment; filename URLEncoder.encode(export.csv, UTF-8));ServletOutputStream out response.getOutputStream();out.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});out.write(st.toString.getBytes(UTF-8));优化有数据时才可以导出
当没有数据时提示无法导出因此返回提示信息ResponseMessage
在有数据可以正常到导出时可能会报错Cannot call sendError() after the response has been committed。
在最后返回null 可成功解决可参考
参考
https://blog.csdn.net/missingshirely/article/details/132339295https://blog.csdn.net/weixin_56567361/article/details/126640185