国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

EasyExcel快速導(dǎo)出 100W 數(shù)據(jù)

這篇具有很好參考價(jià)值的文章主要介紹了EasyExcel快速導(dǎo)出 100W 數(shù)據(jù)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

一. 簡(jiǎn)介

導(dǎo)出是后臺(tái)管理系統(tǒng)的常用功能,當(dāng)數(shù)據(jù)量特別大的時(shí)候會(huì)內(nèi)存溢出和卡頓頁(yè)面,曾經(jīng)自己封裝過(guò)一個(gè)導(dǎo)出,采用了分批查詢數(shù)據(jù)來(lái)避免內(nèi)存溢出和使用SXSSFWorkbook方式緩存數(shù)據(jù)到文件上以解決下載大文件EXCEL卡死頁(yè)面的問(wèn)題。

不過(guò)一是存在封裝不太友好使用不方便的問(wèn)題,二是這些poi的操作方式仍然存在內(nèi)存占用過(guò)大的問(wèn)題,三是存在空循環(huán)和整除的時(shí)候數(shù)據(jù)有缺陷的問(wèn)題,以及存在內(nèi)存溢出的隱患。

無(wú)意間查詢到阿里開(kāi)源的EasyExcel框架,發(fā)現(xiàn)可以將解析的EXCEL的內(nèi)存占用控制在KB級(jí)別,并且絕對(duì)不會(huì)內(nèi)存溢出(內(nèi)部實(shí)現(xiàn)待研究),還有就是速度極快,大概100W條記錄,十幾個(gè)字段,只需要70秒即可完成下載。

遂拋棄自己封裝的,轉(zhuǎn)戰(zhàn)研究阿里開(kāi)源的EasyExcel. 不過(guò) 說(shuō)實(shí)話,當(dāng)時(shí)自己封裝的那個(gè)還是有些技術(shù)含量的,例如:外觀模式,模板方法模式,以及委托思想,組合思想,可以看看。另外,微信搜索關(guān)注Java技術(shù)棧,發(fā)送:設(shè)計(jì)模式,可以獲取我整理的 Java 設(shè)計(jì)模式實(shí)戰(zhàn)教程。

EasyExcel的github地址是:https://github.com/alibaba/easyexcel

二. 案例

2.1 POM依賴

<!-- 阿里開(kāi)源EXCEL -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>easyexcel</artifactId>
    <version>1.1.1</version>
</dependency>

2.2 POJO對(duì)象

package com.authorization.privilege.excel;
 
import java.util.Date;
 
/**
 * @author qjwyss
 * @description
 */
public class User {
 
    private String uid;
    private String name;
    private Integer age;
    private Date birthday;
 
    public User() {
    }
 
    public User(String uid, String name, Integer age, Date birthday) {
        this.uid = uid;
        this.name = name;
        this.age = age;
        this.birthday = birthday;
    }
 
    public String getUid() {
        return uid;
    }
 
    public void setUid(String uid) {
        this.uid = uid;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public Integer getAge() {
        return age;
    }
 
    public void setAge(Integer age) {
        this.age = age;
    }
 
    public Date getBirthday() {
        return birthday;
    }
 
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}

2.3 測(cè)試環(huán)境

2.3.1.數(shù)據(jù)量少的(20W以內(nèi)吧):一個(gè)SHEET一次查詢導(dǎo)出

如果數(shù)據(jù)量過(guò)大,不要用傳統(tǒng)分頁(yè),利用where id> #{lastMaxId} order by id limit 100,解決分頁(yè)慢的問(wèn)題

/**
 * 針對(duì)較少的記錄數(shù)(20W以內(nèi)大概)可以調(diào)用該方法一次性查出然后寫(xiě)入到EXCEL的一個(gè)SHEET中
 * 注意: 一次性查詢出來(lái)的記錄數(shù)量不宜過(guò)大,不會(huì)內(nèi)存溢出即可。
 *
 * @throws IOException
 */
@Test
public void writeExcelOneSheetOnceWrite() throws IOException {

    // 生成EXCEL并指定輸出路徑
    OutputStream out = new FileOutputStream("E:\\temp\\withoutHead1.xlsx");
    ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

    // 設(shè)置SHEET
    Sheet sheet = new Sheet(1, 0);
    sheet.setSheetName("sheet1");

    // 設(shè)置標(biāo)題
    Table table = new Table(1);
    List<List<String>> titles = new ArrayList<List<String>>();
    titles.add(Arrays.asList("用戶ID"));
    titles.add(Arrays.asList("名稱"));
    titles.add(Arrays.asList("年齡"));
    titles.add(Arrays.asList("生日"));
    table.setHead(titles);

    // 查詢數(shù)據(jù)導(dǎo)出即可 比如說(shuō)一次性總共查詢出100條數(shù)據(jù)
    List<List<String>> userList = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        userList.add(Arrays.asList("ID_" + i, "小明" + i, String.valueOf(i), new Date().toString()));
    }

    writer.write0(userList, sheet, table);
    writer.finish();
}

2.3.2.數(shù)據(jù)量適中(100W以內(nèi)):一個(gè)SHEET分批查詢導(dǎo)出

/**
 * 針對(duì)105W以內(nèi)的記錄數(shù)可以調(diào)用該方法分多批次查出然后寫(xiě)入到EXCEL的一個(gè)SHEET中
 * 注意:
 * 每次查詢出來(lái)的記錄數(shù)量不宜過(guò)大,根據(jù)內(nèi)存大小設(shè)置合理的每次查詢記錄數(shù),不會(huì)內(nèi)存溢出即可。
 * 數(shù)據(jù)量不能超過(guò)一個(gè)SHEET存儲(chǔ)的最大數(shù)據(jù)量105W
 *
 * @throws IOException
 */
@Test
public void writeExcelOneSheetMoreWrite() throws IOException {

    // 生成EXCEL并指定輸出路徑
    OutputStream out = new FileOutputStream("E:\\temp\\withoutHead2.xlsx");
    ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

    // 設(shè)置SHEET
    Sheet sheet = new Sheet(1, 0);
    sheet.setSheetName("sheet1");

    // 設(shè)置標(biāo)題
    Table table = new Table(1);
    List<List<String>> titles = new ArrayList<List<String>>();
    titles.add(Arrays.asList("用戶ID"));
    titles.add(Arrays.asList("名稱"));
    titles.add(Arrays.asList("年齡"));
    titles.add(Arrays.asList("生日"));
    table.setHead(titles);

    // 模擬分批查詢:總記錄數(shù)50條,每次查詢20條,  分三次查詢 最后一次查詢記錄數(shù)是10
    Integer totalRowCount = 50;
    Integer pageSize = 20;
    Integer writeCount = totalRowCount % pageSize == 0 ? (totalRowCount / pageSize) : (totalRowCount / pageSize + 1);

    // 注: 此處僅僅為了模擬數(shù)據(jù),實(shí)用環(huán)境不需要將最后一次分開(kāi),合成一個(gè)即可, 參數(shù)為:currentPage = i+1;  pageSize = pageSize
    for (int i = 0; i < writeCount; i++) {

        // 前兩次查詢 每次查20條數(shù)據(jù)
        if (i < writeCount - 1) {

            List<List<String>> userList = new ArrayList<>();
            for (int j = 0; j < pageSize; j++) {
                userList.add(Arrays.asList("ID_" + Math.random(), "小明", String.valueOf(Math.random()), new Date().toString()));
            }
            writer.write0(userList, sheet, table);

        } else if (i == writeCount - 1) {

            // 最后一次查詢 查多余的10條記錄
            List<List<String>> userList = new ArrayList<>();
            Integer lastWriteRowCount = totalRowCount - (writeCount - 1) * pageSize;
            for (int j = 0; j < lastWriteRowCount; j++) {
                userList.add(Arrays.asList("ID_" + Math.random(), "小明", String.valueOf(Math.random()), new Date().toString()));
            }
            writer.write0(userList, sheet, table);
        }
    }

    writer.finish();
}

2.3.3.數(shù)據(jù)量很大(幾百萬(wàn)都行):多個(gè)SHEET分批查詢導(dǎo)出

/**
 * 針對(duì)幾百萬(wàn)的記錄數(shù)可以調(diào)用該方法分多批次查出然后寫(xiě)入到EXCEL的多個(gè)SHEET中
 * 注意:
 * perSheetRowCount % pageSize要能整除  為了簡(jiǎn)潔,非整除這塊不做處理
 * 每次查詢出來(lái)的記錄數(shù)量不宜過(guò)大,根據(jù)內(nèi)存大小設(shè)置合理的每次查詢記錄數(shù),不會(huì)內(nèi)存溢出即可。
 *
 * @throws IOException
 */
@Test
public void writeExcelMoreSheetMoreWrite() throws IOException {

    // 生成EXCEL并指定輸出路徑
    OutputStream out = new FileOutputStream("E:\\temp\\withoutHead3.xlsx");
    ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

    // 設(shè)置SHEET名稱
    String sheetName = "測(cè)試SHEET";

    // 設(shè)置標(biāo)題
    Table table = new Table(1);
    List<List<String>> titles = new ArrayList<List<String>>();
    titles.add(Arrays.asList("用戶ID"));
    titles.add(Arrays.asList("名稱"));
    titles.add(Arrays.asList("年齡"));
    titles.add(Arrays.asList("生日"));
    table.setHead(titles);

    // 模擬分批查詢:總記錄數(shù)250條,每個(gè)SHEET存100條,每次查詢20條  則生成3個(gè)SHEET,前倆個(gè)SHEET查詢次數(shù)為5, 最后一個(gè)SHEET查詢次數(shù)為3 最后一次寫(xiě)的記錄數(shù)是10
    // 注:該版本為了較少數(shù)據(jù)判斷的復(fù)雜度,暫時(shí)perSheetRowCount要能夠整除pageSize, 不去做過(guò)多處理  合理分配查詢數(shù)據(jù)量大小不會(huì)內(nèi)存溢出即可。
    Integer totalRowCount = 250;
    Integer perSheetRowCount = 100;
    Integer pageSize = 20;
    Integer sheetCount = totalRowCount % perSheetRowCount == 0 ? (totalRowCount / perSheetRowCount) : (totalRowCount / perSheetRowCount + 1);
    Integer previousSheetWriteCount = perSheetRowCount / pageSize;
    Integer lastSheetWriteCount = totalRowCount % perSheetRowCount == 0 ?
            previousSheetWriteCount :
            (totalRowCount % perSheetRowCount % pageSize == 0 ? totalRowCount % perSheetRowCount / pageSize : (totalRowCount % perSheetRowCount / pageSize + 1));

    for (int i = 0; i < sheetCount; i++) {

        // 創(chuàng)建SHEET
        Sheet sheet = new Sheet(i, 0);
        sheet.setSheetName(sheetName + i);

        if (i < sheetCount - 1) {

            // 前2個(gè)SHEET, 每個(gè)SHEET查5次 每次查20條 每個(gè)SHEET寫(xiě)滿100行  2個(gè)SHEET合計(jì)200行  實(shí)用環(huán)境:參數(shù):currentPage: j+1 + previousSheetWriteCount*i, pageSize: pageSize
            for (int j = 0; j < previousSheetWriteCount; j++) {
                List<List<String>> userList = new ArrayList<>();
                for (int k = 0; k < 20; k++) {
                    userList.add(Arrays.asList("ID_" + Math.random(), "小明", String.valueOf(Math.random()), new Date().toString()));
                }
                writer.write0(userList, sheet, table);
            }

        } else if (i == sheetCount - 1) {

            // 最后一個(gè)SHEET 實(shí)用環(huán)境不需要將最后一次分開(kāi),合成一個(gè)即可, 參數(shù)為:currentPage = i+1;  pageSize = pageSize
            for (int j = 0; j < lastSheetWriteCount; j++) {

                // 前倆次查詢 每次查詢20條
                if (j < lastSheetWriteCount - 1) {

                    List<List<String>> userList = new ArrayList<>();
                    for (int k = 0; k < 20; k++) {
                        userList.add(Arrays.asList("ID_" + Math.random(), "小明", String.valueOf(Math.random()), new Date().toString()));
                    }
                    writer.write0(userList, sheet, table);

                } else if (j == lastSheetWriteCount - 1) {

                    // 最后一次查詢 將剩余的10條查詢出來(lái)
                    List<List<String>> userList = new ArrayList<>();
                    Integer lastWriteRowCount = totalRowCount - (sheetCount - 1) * perSheetRowCount - (lastSheetWriteCount - 1) * pageSize;
                    for (int k = 0; k < lastWriteRowCount; k++) {
                        userList.add(Arrays.asList("ID_" + Math.random(), "小明1", String.valueOf(Math.random()), new Date().toString()));
                    }
                    writer.write0(userList, sheet, table);

                }
            }
        }
    }

    writer.finish();
}

2.4 生產(chǎn)環(huán)境

2.4.0.Excel常量類

package com.authorization.privilege.constant;
 
/**
 * @author qjwyss
 * @description EXCEL常量類
 */
public class ExcelConstant {
 
    /**
     * 每個(gè)sheet存儲(chǔ)的記錄數(shù) 100W
     */
    public static final Integer PER_SHEET_ROW_COUNT = 1000000;
 
    /**
     * 每次向EXCEL寫(xiě)入的記錄數(shù)(查詢每頁(yè)數(shù)據(jù)大小) 20W
     */
    public static final Integer PER_WRITE_ROW_COUNT = 200000;
 
}
注:為了書(shū)寫(xiě)方便,此處倆個(gè)必須要整除,可以省去很多不必要的判斷。另外如果自己測(cè)試,可以改為100,20。
分享給你: Spring Boot 學(xué)習(xí)筆記。

2.4.1.數(shù)據(jù)量少的(20W以內(nèi)吧):一個(gè)SHEET一次查詢導(dǎo)出

@Override
public ResultVO<Void> exportSysSystemExcel(SysSystemVO sysSystemVO, HttpServletResponse response) throws Exception {

    ServletOutputStream out = null;
    try {
        out = response.getOutputStream();
        ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

        // 設(shè)置EXCEL名稱
        String fileName = new String(("SystemExcel").getBytes(), "UTF-8");

        // 設(shè)置SHEET名稱
        Sheet sheet = new Sheet(1, 0);
        sheet.setSheetName("系統(tǒng)列表sheet1");

        // 設(shè)置標(biāo)題
        Table table = new Table(1);
        List<List<String>> titles = new ArrayList<List<String>>();
        titles.add(Arrays.asList("系統(tǒng)名稱"));
        titles.add(Arrays.asList("系統(tǒng)標(biāo)識(shí)"));
        titles.add(Arrays.asList("描述"));
        titles.add(Arrays.asList("狀態(tài)"));
        titles.add(Arrays.asList("創(chuàng)建人"));
        titles.add(Arrays.asList("創(chuàng)建時(shí)間"));
        table.setHead(titles);

        // 查數(shù)據(jù)寫(xiě)EXCEL
        List<List<String>> dataList = new ArrayList<>();
        List<SysSystemVO> sysSystemVOList = this.sysSystemReadMapper.selectSysSystemVOList(sysSystemVO);
        if (!CollectionUtils.isEmpty(sysSystemVOList)) {
            sysSystemVOList.forEach(eachSysSystemVO -> {
                dataList.add(Arrays.asList(
                        eachSysSystemVO.getSystemName(),
                        eachSysSystemVO.getSystemKey(),
                        eachSysSystemVO.getDescription(),
                        eachSysSystemVO.getState().toString(),
                        eachSysSystemVO.getCreateUid(),
                        eachSysSystemVO.getCreateTime().toString()
                ));
            });
        }
        writer.write0(dataList, sheet, table);

        // 下載EXCEL
        response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName).getBytes("gb2312"), "ISO-8859-1") + ".xls");
        response.setContentType("multipart/form-data");
        response.setCharacterEncoding("utf-8");
        writer.finish();
        out.flush();

    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return ResultVO.getSuccess("導(dǎo)出系統(tǒng)列表EXCEL成功");
}

2.4.2.數(shù)據(jù)量適中(100W以內(nèi)):一個(gè)SHEET分批查詢導(dǎo)出

@Override
public ResultVO<Void> exportSysSystemExcel(SysSystemVO sysSystemVO, HttpServletResponse response) throws Exception {

    ServletOutputStream out = null;
    try {
        out = response.getOutputStream();
        ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

        // 設(shè)置EXCEL名稱
        String fileName = new String(("SystemExcel").getBytes(), "UTF-8");

        // 設(shè)置SHEET名稱
        Sheet sheet = new Sheet(1, 0);
        sheet.setSheetName("系統(tǒng)列表sheet1");

        // 設(shè)置標(biāo)題
        Table table = new Table(1);
        List<List<String>> titles = new ArrayList<List<String>>();
        titles.add(Arrays.asList("系統(tǒng)名稱"));
        titles.add(Arrays.asList("系統(tǒng)標(biāo)識(shí)"));
        titles.add(Arrays.asList("描述"));
        titles.add(Arrays.asList("狀態(tài)"));
        titles.add(Arrays.asList("創(chuàng)建人"));
        titles.add(Arrays.asList("創(chuàng)建時(shí)間"));
        table.setHead(titles);

        // 查詢總數(shù)并 【封裝相關(guān)變量 這塊直接拷貝就行 不要改動(dòng)】
        Integer totalRowCount = this.sysSystemReadMapper.selectCountSysSystemVOList(sysSystemVO);
        Integer pageSize = ExcelConstant.PER_WRITE_ROW_COUNT;
        Integer writeCount = totalRowCount % pageSize == 0 ? (totalRowCount / pageSize) : (totalRowCount / pageSize + 1);

        // 寫(xiě)數(shù)據(jù) 這個(gè)i的最大值直接拷貝就行了 不要改
        for (int i = 0; i < writeCount; i++) {
            List<List<String>> dataList = new ArrayList<>();

            // 此處查詢并封裝數(shù)據(jù)即可 currentPage, pageSize這個(gè)變量封裝好的 不要改動(dòng)
            PageHelper.startPage(i + 1, pageSize);
            List<SysSystemVO> sysSystemVOList = this.sysSystemReadMapper.selectSysSystemVOList(sysSystemVO);
            if (!CollectionUtils.isEmpty(sysSystemVOList)) {
                sysSystemVOList.forEach(eachSysSystemVO -> {
                    dataList.add(Arrays.asList(
                            eachSysSystemVO.getSystemName(),
                            eachSysSystemVO.getSystemKey(),
                            eachSysSystemVO.getDescription(),
                            eachSysSystemVO.getState().toString(),
                            eachSysSystemVO.getCreateUid(),
                            eachSysSystemVO.getCreateTime().toString()
                    ));
                });
            }
            writer.write0(dataList, sheet, table);
        }

        // 下載EXCEL
        response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName).getBytes("gb2312"), "ISO-8859-1") + ".xls");
        response.setContentType("multipart/form-data");
        response.setCharacterEncoding("utf-8");
        writer.finish();
        out.flush();

    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return ResultVO.getSuccess("導(dǎo)出系統(tǒng)列表EXCEL成功");
}

2.4.3.數(shù)據(jù)里很大(幾百萬(wàn)都行):多個(gè)SHEET分批查詢導(dǎo)出

@Override
public ResultVO<Void> exportSysSystemExcel(SysSystemVO sysSystemVO, HttpServletResponse response) throws Exception {

    ServletOutputStream out = null;
    try {
        out = response.getOutputStream();
        ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

        // 設(shè)置EXCEL名稱
        String fileName = new String(("SystemExcel").getBytes(), "UTF-8");

        // 設(shè)置SHEET名稱
        String sheetName = "系統(tǒng)列表sheet";

        // 設(shè)置標(biāo)題
        Table table = new Table(1);
        List<List<String>> titles = new ArrayList<List<String>>();
        titles.add(Arrays.asList("系統(tǒng)名稱"));
        titles.add(Arrays.asList("系統(tǒng)標(biāo)識(shí)"));
        titles.add(Arrays.asList("描述"));
        titles.add(Arrays.asList("狀態(tài)"));
        titles.add(Arrays.asList("創(chuàng)建人"));
        titles.add(Arrays.asList("創(chuàng)建時(shí)間"));
        table.setHead(titles);

        // 查詢總數(shù)并封裝相關(guān)變量(這塊直接拷貝就行了不要改)
        Integer totalRowCount = this.sysSystemReadMapper.selectCountSysSystemVOList(sysSystemVO);
        Integer perSheetRowCount = ExcelConstant.PER_SHEET_ROW_COUNT;
        Integer pageSize = ExcelConstant.PER_WRITE_ROW_COUNT;
        Integer sheetCount = totalRowCount % perSheetRowCount == 0 ? (totalRowCount / perSheetRowCount) : (totalRowCount / perSheetRowCount + 1);
        Integer previousSheetWriteCount = perSheetRowCount / pageSize;
        Integer lastSheetWriteCount = totalRowCount % perSheetRowCount == 0 ?
                previousSheetWriteCount :
                (totalRowCount % perSheetRowCount % pageSize == 0 ? totalRowCount % perSheetRowCount / pageSize : (totalRowCount % perSheetRowCount / pageSize + 1));


        for (int i = 0; i < sheetCount; i++) {

            // 創(chuàng)建SHEET
            Sheet sheet = new Sheet(i, 0);
            sheet.setSheetName(sheetName + i);

            // 寫(xiě)數(shù)據(jù) 這個(gè)j的最大值判斷直接拷貝就行了,不要改動(dòng)
            for (int j = 0; j < (i != sheetCount - 1 ? previousSheetWriteCount : lastSheetWriteCount); j++) {
                List<List<String>> dataList = new ArrayList<>();

                // 此處查詢并封裝數(shù)據(jù)即可 currentPage, pageSize這倆個(gè)變量封裝好的 不要改動(dòng)
                PageHelper.startPage(j + 1 + previousSheetWriteCount * i, pageSize);
                List<SysSystemVO> sysSystemVOList = this.sysSystemReadMapper.selectSysSystemVOList(sysSystemVO);
                if (!CollectionUtils.isEmpty(sysSystemVOList)) {
                    sysSystemVOList.forEach(eachSysSystemVO -> {
                        dataList.add(Arrays.asList(
                                eachSysSystemVO.getSystemName(),
                                eachSysSystemVO.getSystemKey(),
                                eachSysSystemVO.getDescription(),
                                eachSysSystemVO.getState().toString(),
                                eachSysSystemVO.getCreateUid(),
                                eachSysSystemVO.getCreateTime().toString()
                        ));
                    });
                }
                writer.write0(dataList, sheet, table);
            }
        }

        // 下載EXCEL
        response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName).getBytes("gb2312"), "ISO-8859-1") + ".xls");
        response.setContentType("multipart/form-data");
        response.setCharacterEncoding("utf-8");
        writer.finish();
        out.flush();

    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return ResultVO.getSuccess("導(dǎo)出系統(tǒng)列表EXCEL成功");
}

三、總結(jié)

造的假數(shù)據(jù),100W條記錄,18個(gè)字段,測(cè)試導(dǎo)出是70s。在實(shí)際上產(chǎn)環(huán)境使用的時(shí)候,具體的還是要看自己寫(xiě)的sql的性能。sql性能快的話,會(huì)很快。

有一點(diǎn)推薦一下:在做分頁(yè)的時(shí)候使用單表查詢, 對(duì)于所需要處理的外鍵對(duì)應(yīng)的冗余字段,在外面一次性查出來(lái)放到map里面(推薦使用@MapKey注解),然后遍歷list的時(shí)候根據(jù)外鍵從map中獲取對(duì)應(yīng)的名稱。

一個(gè)宗旨:少發(fā)查詢sql, 才能更快的導(dǎo)出。

題外話:如果數(shù)據(jù)量過(guò)大,不要用傳統(tǒng)分頁(yè),利用where id> #{lastMaxId} order by id limit 100,解決分頁(yè)慢的問(wèn)題文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-795635.html

到了這里,關(guān)于EasyExcel快速導(dǎo)出 100W 數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Java 利用Easyexcel動(dòng)態(tài)導(dǎo)出表頭列

    Java 利用Easyexcel動(dòng)態(tài)導(dǎo)出表頭列

    其中 fieldName 為要導(dǎo)出的字段名稱 也就是 數(shù)據(jù)對(duì)象 中與之對(duì)應(yīng)的字段名稱 headName 為與字段對(duì)應(yīng)的表頭(我這里默認(rèn)用的就是導(dǎo)出表頭集合中字段排序就是導(dǎo)出的表頭排序 如有需要,可以自己定義導(dǎo)出表頭順序) 導(dǎo)出util類,直接上代碼 其中? CellStyle() 是設(shè)置的默認(rèn)樣式?

    2024年02月11日
    瀏覽(20)
  • 測(cè)試開(kāi)發(fā)工程師的薪資上限究竟在哪?年薪100W都不是夢(mèng)...

    測(cè)試開(kāi)發(fā)工程師的薪資上限究竟在哪?年薪100W都不是夢(mèng)...

    在說(shuō)測(cè)試開(kāi)發(fā)工程師的薪資待遇之前,咱們要先了解軟件測(cè)試崗位是用來(lái)做什么的,崗位是否重要,只有你知道了這些,才能判斷這個(gè)崗位是否有價(jià)值! 軟件測(cè)試是依據(jù)需求分析和測(cè)試用例,運(yùn)用手工和自動(dòng)化的手段來(lái)驗(yàn)證實(shí)際結(jié)果與預(yù)期結(jié)果是否一致! 淺層次理解為就是

    2023年04月11日
    瀏覽(21)
  • Java——使用EasyExcel導(dǎo)出動(dòng)態(tài)列的Excel

    多多點(diǎn)贊,會(huì)變好看! 多多留言,會(huì)變有錢! 有些時(shí)候列表的列可能是動(dòng)態(tài)的,需要根據(jù)動(dòng)態(tài)表頭導(dǎo)出Excel文件,這時(shí)候可以使用下面的方法解決: 靜態(tài)列導(dǎo)出代碼:

    2024年02月15日
    瀏覽(34)
  • 【JAVA】easyexcel 導(dǎo)出excel文件帶多個(gè)圖片

    【JAVA】easyexcel 導(dǎo)出excel文件帶多個(gè)圖片

    最終效果 ?pom版本 實(shí)現(xiàn)代碼 ?

    2024年02月16日
    瀏覽(27)
  • java實(shí)現(xiàn)excel的導(dǎo)出之使用easyExcel

    java實(shí)現(xiàn)excel的導(dǎo)出之使用easyExcel

    在我們的項(xiàng)目需求中,經(jīng)常會(huì)遇到導(dǎo)出的需求,其中excel的導(dǎo)出最為常見(jiàn)。生成Excel比較有名的框架有Apache poi,jxl等,但他們都存在一個(gè)嚴(yán)重的問(wèn)題就是非常的耗內(nèi)存,如果你的系統(tǒng)并發(fā)量不大的話可能還行,但是一旦并發(fā)上來(lái)后一定會(huì)OOM或者JVM頻繁的full gc. EasyExcel是阿里巴巴

    2024年02月15日
    瀏覽(24)
  • Java 導(dǎo)出Excel表格生成下拉框-EasyExcel
  • Java 使用 EasyExcel 實(shí)現(xiàn)導(dǎo)入導(dǎo)出(新手篇教程)

    Java 使用 EasyExcel 實(shí)現(xiàn)導(dǎo)入導(dǎo)出(新手篇教程)

    官網(wǎng)鎮(zhèn)樓↓,覺(jué)得我寫(xiě)的不好的同學(xué)可以去官網(wǎng)看哦 EasyExcel 示例: 如上一個(gè)簡(jiǎn)易 Excel 表格,表頭占了兩行,且第三列開(kāi)始才為有效數(shù)據(jù),那么我們應(yīng)該如何導(dǎo)入? 建造實(shí)體類 首先無(wú)論是導(dǎo)入還是導(dǎo)出,都需要先建對(duì)應(yīng)的實(shí)體類 ?如圖所示,因?yàn)槲业氖纠?Excel 一共需要讀

    2024年04月17日
    瀏覽(29)
  • EasyExcel導(dǎo)入和導(dǎo)出數(shù)據(jù)

    EasyExcel導(dǎo)入和導(dǎo)出數(shù)據(jù)

    1.cmtroller 調(diào)用service方法,完成導(dǎo)出 2.service 調(diào)用工具類的方法完成導(dǎo)出 傳入response,標(biāo)題控制類(標(biāo)題名稱,合并的列數(shù)),員工列表,文件名稱,excel的標(biāo)題名稱,要導(dǎo)出的數(shù)據(jù)類 3.工具類中的方法 4.控制標(biāo)題類 這個(gè)類控制數(shù)據(jù)之前的顯示內(nèi)容 效果 2022-10-28 亂碼解決 因?yàn)槲募?/p>

    2023年04月09日
    瀏覽(23)
  • 【Java結(jié)合EasyExcel,模板文件填充并導(dǎo)出Excel】

    【Java結(jié)合EasyExcel,模板文件填充并導(dǎo)出Excel】

    需求描述: 客戶網(wǎng)頁(yè)上填一個(gè)Excel表格,數(shù)據(jù)存到數(shù)據(jù)庫(kù),這個(gè)導(dǎo)出接口要做的就是從數(shù)據(jù)庫(kù)中的獲取數(shù)據(jù)并填充到模板文件,最后通過(guò)response返給前端一個(gè)下載鏈接,用戶即可獲取填充好的Excel文件。 方案一: 一開(kāi)始使用的是easypoi,發(fā)現(xiàn)當(dāng)填充一行數(shù)據(jù)時(shí)是OK的,但是如果

    2024年02月09日
    瀏覽(28)
  • 數(shù)據(jù)導(dǎo)入導(dǎo)出(POI以及easyExcel)

    數(shù)據(jù)導(dǎo)入導(dǎo)出(POI以及easyExcel)

    ????????將一些數(shù)據(jù)庫(kù)信息導(dǎo)出為Excel表格 ????????將Excel表格數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù) ? ? ? ? 大量數(shù)據(jù)的導(dǎo)入導(dǎo)出操作 常?的解決?案為: Apache POI 與阿?巴巴 easyExcel Apache POI 是基于 Office Open XML 標(biāo)準(zhǔn)( OOXML )和 Microsoft 的 OLE 2 復(fù)合?檔 格式( OLE2 )處理各種?件格式的

    2024年02月13日
    瀏覽(21)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包