|
|
@@ -1,18 +1,20 @@
|
|
|
package com.mrxu.framework.boot.web;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.mrxu.framework.boot.bean.LayuiPage;
|
|
|
import com.mrxu.framework.boot.bean.PageResult;
|
|
|
import com.mrxu.framework.boot.bean.ResponseObj;
|
|
|
import com.mrxu.framework.common.util.BaseCode;
|
|
|
+import com.mrxu.framework.common.util.BusinessException;
|
|
|
import com.mrxu.framework.common.util.StrFunc;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -235,4 +237,24 @@ public class BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ * @param response
|
|
|
+ * @param fileName
|
|
|
+ * @param clazz
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ public void export(HttpServletResponse response,String fileName,Class<?> clazz,Collection<?> data) {
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
|
|
+ EasyExcel.write(response.getOutputStream()).head(clazz).sheet("sheet1").doWrite(data);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ log.error("导出Excel异常",e);
|
|
|
+ throw new BusinessException("导出Excel异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|