开发者学堂课程【分布式数据库 HBase 快速入门:初始化页面微博内容】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/101/detail/1783
初始化页面微博内容
//获取微博内容(初始化页面)
public static void getInit ( String uid ) throws IOException{
//获取连接
Connection connection = ConnectionFactory .createConnection ( configuration );
//获取表对象(2个)
Table inboxTable= connection . getTable ( TableName . valueor ( Constant . IBOn );
Table contTable =connection . getTable ( TableNane . valueOr ( Constant . CoNTENTn );
//获取收件箱表数据
Get get = new Get( Bytes . toBytes ( uid ));//收件箱表get对象
Result result = inboxTable . get ( get );//设置获取最大版本的数据
Result result = inboxTable . get ( get );
ArrayList < Get > gets " new ArrayList <>();
Cell[] cells = result .rawCells0:
//遍历返回内容并将其封装成内容的 get 对 象
for ( Cell cell : cells ){
Get contGet = new Get ( CellUtil . clonelalue(cell)):
gets . add ( eontGet );
//根据收件箱获取值去往内容表获取微博内容
Result [] results = contTable . get ( gets );
for ( Result result1: results ){
Ce11[]cells1=result1.rawCells();
//遍历打印
for ( Cell cel1:cells1){
System . out . println (" RK :”+ Bytes . toString (CellUtil. cloneRoa (cel1))
+", Content ;”+ Bytes . toString (Cel1Util. clonelalue (cel1)))
}
}
//关闭资源
inboxTable .close0: contTable .close();
connection . close ();
Connection. Close();
}