|
@@ -13,6 +13,7 @@
|
|
package ${packageName}.${moduleName}.modular.${busName}.controller;
|
|
package ${packageName}.${moduleName}.modular.${busName}.controller;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
@@ -121,25 +122,25 @@ public class ${className}Controller {
|
|
* @param sheetName 表格名称
|
|
* @param sheetName 表格名称
|
|
*/
|
|
*/
|
|
public void exportExcel(HttpServletResponse response, Class cl, List data, String sheetName){
|
|
public void exportExcel(HttpServletResponse response, Class cl, List data, String sheetName){
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
|
- try {
|
|
|
|
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
|
- String fileName = URLEncoder.encode(sheetName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
|
- response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
|
- EasyExcel.write(response.getOutputStream(), cl).autoCloseStream(Boolean.FALSE).sheet(sheetName).doWrite(data);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- response.reset();
|
|
|
|
- response.setContentType("application/json");
|
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
|
- map.put("status", "failure");
|
|
|
|
- map.put("message", "下载文件失败" + e.getMessage());
|
|
|
|
- try {
|
|
|
|
- response.getWriter().println(JSON.toJSONString(map));
|
|
|
|
- } catch (IOException ex) {
|
|
|
|
- ex.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
|
+ try {
|
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + URLUtil.encode(sheetName) + ".xlsx");
|
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
+ response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
|
+ EasyExcel.write(response.getOutputStream(), cl).autoCloseStream(Boolean.FALSE).sheet(sheetName).doWrite(data);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setContentType("application/json");
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ map.put("status", "failure");
|
|
|
|
+ map.put("message", "下载文件失败" + e.getMessage());
|
|
|
|
+ try {
|
|
|
|
+ response.getWriter().println(JSON.toJSONString(map));
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|