列表导出至excel

 <button class="btn btn-sm btn-danger" type="button" id="exportBatchBtn">
    <i class="fa fa-trash fa-btn"></i>批量导出
 </button>
   //批量导出
        $("#exportBatchBtn").click(function () {
            var ids = "";
            $(".check").each(function () {
                if ($(this).prop("checked")) {
                    ids = ids + ($(this).val()) + ","
                }
            });
            if (ids == "") {
                top.layer.msg("请选择要导出的数据!");
                return false;
            } else {
                ids = ids.substr(0, ids.length - 1);
                location.href = "<%=basePath%>dispatch/exportByIds?ids="+ids;
            }
        });
    @KrtLog(description = "批量导出发文数据")
    @GetMapping("dispatch/exportByIds")
    public void exportByIds(HttpServletResponse response, String ids, OutputStream os) throws Exception {
        List lists = dispatchFileService.exportByIds(ids);
        //定义导出参数
        ExportParams params = new ExportParams();
        params.setTitle("发文数据");
        Workbook workbook =  ExcelExportUtil.exportExcel(params, Dispatch_export.class, lists);
        String fname = "发文数据"+ DateUtil.dateToString("yyyy-MM-dd", new Date());
        fname = URLEncoder.encode(fname,"UTF-8");
        response.reset();//清空输出流
        response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式
        response.setHeader("Content-Disposition","attachment;filename="+new String(fname.getBytes("UTF-8"),"GBK")+".xls");
        response.setContentType("application/msexcel");//定义输出类型
        //将文件写入输出流
        workbook.write(os);
        workbook.close();
        os.close();
    }
 public List exportByIds(String idsStr){
        List lists = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        if (!Assert.isEmpty(idsStr)) {
            String[] ids = idsStr.split(",");
            List<Dispatch> dispatchList = dispatchFileMapper.exportByIds(ids);
            for(int i = 0;i<dispatchList.size();i++) {
                Dispatch_export export = new Dispatch_export();
                export.setId(i+1);
                export.setYear(sdf.format(new Date()));
                export.setFileTitle(dispatchList.get(i).getFileTitle());
                export.setName(dispatchList.get(i).getFullName());
                export.setInsertTime(DateUtil.dateToString("yyyy-MM-dd HH:mm:ss",dispatchList.get(i).getInsertTime()));
                lists.add(export);
            }
        }
        return lists;
    }
 List exportByIds(String[] ids);
<select id="exportByIds" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from process_dispatch where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
原文地址:https://www.cnblogs.com/jietz0407-com/p/8430018.html