• 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();
        }
    }
  • 相关阅读:
    PHP PSR 标准规范
    PHP线程安全与非线程安全的区别(NTS/TS)选择?
    goto 语法在 PHP 中的使用
    linux命令post请求发送json串
    接口日志表sql【我】
    sentinel最简单接入【我】
    Jps命令—使用详解
    MyBatis-Plus Wrapper条件构造器查询大全
    IDEA项目启动不起来也不打印日志【我】
    linux下查看nginx配置文件地址
  • 原文地址:https://www.cnblogs.com/Doduo/p/11731345.html
Copyright © 2020-2023  润新知