zoukankan      html  css  js  c++  java
  • vue post下载

    前端:

    postExcelFile(params, url) {
        // params是post请求需要的参数,url是请求url地址
        const form = document.createElement('form');
        form.style.display = 'none';
        form.action = url;
        form.method = 'post';
        document.body.appendChild(form);
        // 动态创建input并给value赋值
        /* eslint-disable-next-line */
        for (const key in params) {
            if (params[key]) {
                const input = document.createElement('input');
                input.type = 'hidden';
                input.name = key;
                input.value = params[key];
                form.appendChild(input);
            }
        }
    
        form.submit();
        form.remove();
    },
    // 导出
    exportExcel() {
        this.postExcelFile(
            this.searchForm,
            '/eya-pos/posDeal/exportExcel',
        );
    },

    后台:

    @PostMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response,String sku,Integer dealStatus){
        DealSearch dealSearch = new DealSearch();
        dealSearch.setSku(sku);
        dealSearch.setDealStatus(dealStatus);
        
        List<DealExport> exportList = iPosDealsService.findExportList(dealSearch);
        String template = 'template/PosSeckillActivityDealTemplate.xlsx';
        AsposeUtils.registerCells();
        try {
            InputStream templateStream = this.getClass().getClassLoader().getResourceAsStream(template);
            OutputStream outputStream = response.getOutputStream();
            Workbook workbook = new Workbook(templateStream);
            WorkbookDesigner designer = new WorkbookDesigner();
            designer.setWorkbook(workbook);
            designer.setDataSource("ExportList",exportList);
            designer.process();
            response.setContentType("application/force-download");
            String fileName = "Deal活动导出" + DateTimeUtils.getNowSimpleDateTime() + ".xlsx";
            response.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));
            workbook.save(outputStream,workbook,getFileFormat());
            outputStream.flush();
            outputStream.close();
        }
        catch (IOException ix){
            ix.printStackTrace();
        }
    }
  • 相关阅读:
    P3146 [USACO16OPEN]248
    P2590 [ZJOI2008]树的统计
    P3379 【模板】最近公共祖先(LCA)
    P2253 好一个一中腰鼓!
    数组中出现次数超过一半的数字
    字符串的排列
    二叉搜索树与双向链表
    二叉搜索树的后序遍历序列
    从上往下打印二叉树
    顺时针打印矩阵
  • 原文地址:https://www.cnblogs.com/Doduo/p/11731345.html
Copyright © 2011-2022 走看看