多条件筛选后的结果,导出到excel表

如图,通过条件搜索后筛选出来的结果,点击导出,导出到Excel表格。条件可以是为空,可以一个或者多个条件。这个具体怎么实现?越详细越好,谢谢!
图片说明

点击导出时从后台重现查询一遍数据库,将需要的数据导出

点击导出,把筛选条件带入后台,使用这些条件执行sql,查出结果写入excel中

第一步,查询数据库,返回对象集合
第二部,根据集合生成excel(百度使用poi创建excel,最终将excel转换成字节数组)
try(ByteArrayOutputStream baos = new ByteArrayOutputStream()){
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("学习考试记录");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框

        HSSFCellStyle styleTitle = wb.createCellStyle();
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_DOTTED);//下边框
        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_DOTTED);//左边框
        styleTitle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
        styleTitle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
        //设置表头  第一行
        HSSFCell cell = null;
        cell = row.createCell(0);
        cell.setCellValue("姓名");
        cell.setCellStyle(styleTitle);

        cell = row.createCell(1);
        cell.setCellValue("性别");
        cell.setCellStyle(styleTitle);

        //填充表格第二行第一列的内容,其他内容一样的方式,循环写入内容
        row = sheet.createRow((int) 1);
        cell = row.createCell(1);
        cell.setCellValue("内容");
        cell.setCellStyle(style);

        wb.write(baos);
        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    }

第三步,设置http响应头,(
"Content-Type"=="application/vnd.ms-excel;charset=utf-8"
"Content-Disposition"=="attachment;filename=表名.xls")
第四步,将得到的字节数组写入到http响应中.

页面请求
下载