学习时长:3h
解决问题:今天学习了一些HBASE关于java的api
代码量:150行
/**
* 查全部数据
* @param tableName
* @return
* @throws IOException
*/
public static ArrayList<Pojo> scanAll(String tableName) throws IOException { Table table = connection.getTable(TableName.valueOf(tableName)); Scan scan = new Scan(); ArrayList<Pojo> pojos = new ArrayList<>(); ResultScanner resultScanner = table.getScanner(scan); for (Result result : resultScanner) { Pojo pojo = new Pojo(); //将数据值放到一个数组中 List<Cell> cells = result.listCells(); pojo.setCz(Bytes.toString(cells.get(0).getValueArray(),cells.get(0).getValueOffset(),cells.get(0).getValueLength())); pojo.setDwwz(Bytes.toString(cells.get(1).getValueArray(),cells.get(1).getValueOffset(),cells.get(1).getValueLength())); pojo.setDzyx(Bytes.toString(cells.get(2).getValueArray(),cells.get(2).getValueOffset(),cells.get(2).getValueLength())); pojo.setFrdb(Bytes.toString(cells.get(3).getValueArray(),cells.get(3).getValueOffset(),cells.get(3).getValueLength())); pojo.setGddh(Bytes.toString(cells.get(4).getValueArray(),cells.get(4).getValueOffset(),cells.get(4).getValueLength())); pojo.setGkglbm(Bytes.toString(cells.get(5).getValueArray(),cells.get(5).getValueOffset(),cells.get(5).getValueLength())); pojo.setJgjj(Bytes.toString(cells.get(6).getValueArray(),cells.get(6).getValueOffset(),cells.get(6).getValueLength())); pojo.setJgmc(Bytes.toString(cells.get(7).getValueArray(),cells.get(7).getValueOffset(),cells.get(7).getValueLength())); pojo.setJsxqmc(Bytes.toString(cells.get(8).getValueArray(),cells.get(8).getValueOffset(),cells.get(8).getValueLength())); pojo.setJgsx(Bytes.toString(cells.get(9).getValueArray(),cells.get(9).getValueOffset(),cells.get(9).getValueLength())); pojo.setLxr(Bytes.toString(cells.get(10).getValueArray(),cells.get(10).getValueOffset(),cells.get(10).getValueLength())); pojo.setSzdy(Bytes.toString(cells.get(11).getValueArray(),cells.get(11).getValueOffset(),cells.get(11).getValueLength())); pojo.setTxdz(Bytes.toString(cells.get(12).getValueArray(),cells.get(12).getValueOffset(),cells.get(12).getValueLength())); pojo.setYddh(Bytes.toString(cells.get(13).getValueArray(),cells.get(13).getValueOffset(),cells.get(13).getValueLength())); pojo.setYzbm(Bytes.toString(cells.get(14).getValueArray(),cells.get(14).getValueOffset(),cells.get(14).getValueLength())); //System.out.println(pojo); pojos.add(pojo); } /* for (Pojo pojo : pojos) { System.out.println(pojo); } */ table.close(); return pojos; }
标签:getValueOffset,23,软工,get,Bytes,pojo,16,toString,cells From: https://www.cnblogs.com/kun1790051360/p/17706935.html