layui下载导出

后台就是一个查询  返回数据的

    //下载
    @PostMapping("vonrDefective/downloadExcel")
    @ResponseBody
    public String poorUserRepairListPostList(@RequestBody(required=false) VonrDefective vonrDefective) {
        List<VonrDefective> list = vonrDefectiveService.findVonrDefectives(vonrDefective);
//        List<Map<String,String>> mapList = new ArrayList<>();
//        for(VonrDefective vonrDefective1:list){
//            Map<String,String> map = new HashMap<>();
//
//            map.put("city",vonrDefective1.getCity());
//            map.put("cgi",vonrDefective1.getCgi());
//            map.put("cellName",vonrDefective1.getCellName());
//            map.put("usersAll",vonrDefective1.getUsersAll());
//            map.put("usersDefective",vonrDefective1.getUsersDefective());
//            map.put("usersDefectiveProportion",vonrDefective1.getUsersDefectiveProportion());
//            map.put("usersArpu",vonrDefective1.getUsersArpu());
//            map.put("startTime",vonrDefective1.getStartTime());
//            map.put("endTime",vonrDefective1.getEndTime());
//            map.put("createTime",vonrDefective1.getCreateTime());
//            mapList.add(map);
//        }
        return JSONObject.toJSONString(list);
    }

前端

//导出按钮
        $("#export1").click(function () {
            var loading = layer.msg('正在导出...', {icon: 16, shade: 0.3, time: 0});
            var data = {
                "cellName": $("#cellName").val()
            }
            $.ajax({
                url: "/vonrDefective/downloadExcel",
                type: 'POST',
                data: JSON.stringify(data),
                cache: false,
                async: true,
                dataType: "json",
                contentType: 'application/json',
                success: function (result) {
                    table.exportFile(tableIns.config.id, result, 'xlsx');
                    layer.close(loading);
                    layer.msg("导出完成");
                }
            });
            return false;
        })

猜你喜欢

转载自blog.csdn.net/qq_37889636/article/details/129254802