ArrayList<List<Object>> lists = new ArrayList<List<Object>>(); List<HashMap<String, String>> mapList = new ArrayList<HashMap<String, String>>(); Charset charset = Charset.forName("GBK"); DBFReader dbfReader = new DBFReader(file.getInputStream(), charset);//编码字符集 int fieldCount = dbfReader.getFieldCount();//获取字段数量 List<Object> fieldNameList = new ArrayList<Object>(); for (int i = 0; i < fieldCount; i++) { fieldNameList.add(dbfReader.getField(i).getName());//表头数据 } Object[] values; while ((values = dbfReader.nextRecord()) != null) {//获取所有数据信息 ArrayList<Object> list = new ArrayList<Object>(); for (Object value : values) { list.add(value); } lists.add(list); } for (int index = 0; index < lists.size(); index++) { List<Object> eveExcelData = lists.get(index); HashMap<String, String> dataMap = getImportArchivalDataExcelFieldValue(fieldNameList, eveExcelData); mapList.add(dataMap); } dbfReader.close(); //*分页*//* int count = mapList.size(); // 总记录数 // 计算总页数 int pages = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; // 起始位置 int start = pageNum <= 0 ? 0 : (pageNum > pages ? (pages - 1) * pageSize : (pageNum - 1) * pageSize); // 终止位置 int end = pageNum <= 0 ? (pageSize <= count ? pageSize : count) : (pageSize * pageNum <= count ? pageSize * pageNum : count); CommonPage objectCommonPage = new CommonPage<>(); objectCommonPage.setPageNum(pageNum); objectCommonPage.setPageSize(pageSize); objectCommonPage.setTotal(Long.valueOf(mapList.size())); objectCommonPage.setTotalPage((mapList.size() + pageSize - 1) / pageSize); objectCommonPage.setList(mapList.subList(start, end)); return objectCommonPage;
DBF文件读取+分页
最新推荐文章于 2024-04-17 15:52:58 发布