コード例 #1
0
 private void updateExportResult() {
   JdbcTemplate writeJt = DBUtil.getWriteJdbcTemplate(connectUrls);
   writeResult(
       writeJt,
       resultProcedure,
       this.params,
       "http://" + this.ip + ":" + this.port + "/export/download/" + fileName,
       "");
 }
コード例 #2
0
  @Override
  public void run() {
    try {
      int total = getCount(jt, queryProcedure); // 总记录数
      if (total == 0) {
        throw new Exception("没有能导出的数据!");
      }

      double totalPages = getPages(total);

      SXSSFWorkbook wb = null;
      FileInputStream fis = null;

      for (int i = 0; i < totalPages; i++) { // 总共要查询数据库的次数
        List<Map<String, Object>> list = query(jt, queryProcedure, pageCount, i + 1); // 查询分页数据
        if (list != null && list.size() != 0) {
          if (this.titles == null) { // 设置标题数组,方便以后使用
            handleTitles(list); // 处理标题数组
          }

          File file = new File(filePath);
          if (!file.exists()) {
            wb = createWorkbook(); // 生成excel对象
          }
          POIUtil.exportPerpareShit(list, wb, this.titles); // 将本分页数据写入excel对象
        }
      }
      writeToFile(wb); // 将excel对象写入硬盘的excel文件

      updateExportResult(); // 更新导出结果

    } catch (Exception e) {
      JdbcTemplate writeJt = DBUtil.getWriteJdbcTemplate(connectUrls);
      writeResult(writeJt, resultProcedure, this.params, "", e.getMessage());
    }
  }