1、通过控制台或者客户端,在TableStore中新建了实例owlforest,在实例详情中获取到实例访问地址endPoint

2、新建表user,确定主键为userid(Interger)类型,因为TableStore最多支持4个主键,这里先尝试一个主键的情况。

3、通过控制台新增数据

4、修改pom.xml

<dependency>
    <groupId>com.aliyun.openservices</groupId>
    <artifactId>tablestore</artifactId>
    <version>4.10.2</version>
</dependency>

5、通过主键,用getRow获取一行数据(使用默认配置创建 SyncClient)

package com.aliyun.demo.controller;

import com.alicloud.openservices.tablestore.SyncClient;
import com.alicloud.openservices.tablestore.model.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Tablestore {

    final String endPoint = "实例访问地址";
    final String accessKeyId = "accessKeyId";
    final String accessKeySecret = "accessKeySecret";
    final String instanceName = "实例名";

    @RequestMapping("/query")
    public String query() {
        SyncClient client = new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName);
        GetRowRequest rowRequest = new GetRowRequest();

        SingleRowQueryCriteria queryCriteria = new SingleRowQueryCriteria("user");
        //读取数据时,返回的最多版本个数。
        queryCriteria.setMaxVersions(5);
        //主键
        PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
        primaryKeyBuilder.addPrimaryKeyColumn("userid", PrimaryKeyValue.fromLong(2));
        queryCriteria.setPrimaryKey(primaryKeyBuilder.build());

        rowRequest.setRowQueryCriteria(queryCriteria);
        GetRowResponse rowResponse = client.getRow(rowRequest);
        if(rowResponse == null){
            return "未获取到TableStore的数据";
        }else{
            String responseMsg = "";
            Column[] cols = rowResponse.getRow().getColumns();
            for (Column col : cols){
                System.out.println(col.getName());
                System.out.println(col.getValue());
                responseMsg = responseMsg + "Name:" + col.getName() + ",Value:" + col.getValue() + ", ";
            }
            return responseMsg;
        }
    }
}

采用自定义配置的方式创建SyncClient

ClientConfiguration clientConfiguration = new ClientConfiguration();
// 设置建立连接的超时时间。
clientConfiguration.setConnectionTimeoutInMillisecond(5000);
// 设置socket超时时间。
clientConfiguration.setSocketTimeoutInMillisecond(5000);
// 设置重试策略,若不设置,采用默认的重试策略。
clientConfiguration.setRetryStrategy(new AlwaysRetryStrategy());
// 其他配置项省略
SyncClient client = new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName, clientConfiguration);

6、结果

TableStore:创建SyncClient+getRow读取一行数据的更多相关文章

  1. c++从文件中读取一行数据并保存在数组中

    从txt文本中读取数据存入数组中 #include <iostream> #include <fstream> #include <string> #include ...

  2. xml读取一行数据

    #include<map>#include<iostream>#include<fstream>#include<string>using namesp ...

  3. C/C++程序从文本文件中读取(保存)数据

    :本文仅供初学者参阅,解惑 在C程序中: 与程序代码外的数据(文件)打交道,我们使用到流(stream)这个概念,实现进程的虚拟内存与文件之间的数据交换. ——文件流:C标准库提供了FILE(之所以命 ...

  4. 【转】fscanf 跳过空格,读取一行

    fscanf(fp, "%s", sLineWord); 以上语句,在读取一行数据时,如何遇到该行数据有空格,那么读到空格处就停止,不再继续向下读. 若想遇到空格继续读取,读取完整 ...

  5. Python读取文件数据

    1题目要求: 文本文件有这些数据,需要的只有其中的5个属性,如下颜色标记 像以下的数据达到75万组: 1product/productId: B0000UIXZ4 2product/title: Ti ...

  6. 在MVC中动态读取JSON数据创建表格

    //使用getJSON // ("@Url.Action("GetAllUsers","User")" ,json文件的路径.也可以是 /M ...

  7. jxl读写excel, poi读写excel,word, 读取Excel数据到MySQL

    这篇blog是介绍: 1. java中的poi技术读取Excel数据,然后保存到MySQL数据中. 2. jxl读写excel 你也可以在 : java的poi技术读取和导入Excel了解到写入Exc ...

  8. Java读取Excel数据

    Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 下图是excel文件的路径和文件名 下图是exce ...

  9. poi——读取excel数据

    单元格类型 读取Excel数据 package com.java.test.poi; import java.io.File; import java.io.FileInputStream; impo ...

随机推荐

  1. PHP socket 服务器框架集

    1.Swoole:重新定义PHP PHP语言的高性能网络通信框架,提供了PHP语言的异步多线程服务器,异步TCP/UDP网络客户端,异步MySQL,数据库连接池,AsyncTask,消息队列,毫秒定时 ...

  2. java降低竞争锁的一些方法

    序本文介绍一下提升并发可伸缩性的一些方式:减少锁的持有时间,降低锁的粒度,锁分段.避免热点域以及采用非独占的锁或非阻塞锁来代替独占锁. 减少锁的持有时间降低发生竞争可能性的一种有效方式就是尽可能缩短锁 ...

  3. 使用MATLAB对数据进行位操作以及RGB图片显示

    fd = fopen('video_test_pattern_avalon_generator_source_data.txt'); //打开像素源文件 A = fscanf(fd,'%d'); // ...

  4. 关于libusb-win32开发的经验

    引用:http://blog.sina.com.cn/s/blog_4b4b54da010153zb.html 作为设备开发者, 一般需要让设备与上位机PC通讯, 我们往往考虑采用以下几种接口: rs ...

  5. Python多版本共存virtualenv配置

    virtualenv 前提是已经安装好了python.我的ubuntu是自带了python2.7和python3.6 安装vrtualenv sudo apt-get install python-v ...

  6. gitlab ssh clone问题解决

    公司搭建的gitlab,通过http协议可以clone: [sisi@pre-srv24 gitlab]$ git clone http://gitlab.test.mycompany.com/dev ...

  7. 【转】non-blocking REST services with Spring MVC

    堵塞Controller Controller为单例: 非线程安全: 堵塞方式: 1个request对应1个处理Thread: @RestController public class Process ...

  8. 使用R语言-计算均值,方差等

    R语言对于数值计算很方便,最近用到了计算方差,标准差的功能,特记录. 数据准备 height <- c(6.00, 5.92, 5.58, 5.92) 1 计算均值 mean(height) [ ...

  9. Notepad++ 中使用tail -f功能

    想要notepad++中有tail -f的功能吗? 可以如下配置 Settings > Preferences > MISC 在 File Status Auto-Detection下 “ ...

  10. 写在vue总结之前(一)

    在大概2016年6月吧,知道了vue,博客园有个博主用vue写了一个不算完整的博客园app,做出来的效果相比博客园原本的app看上去要华丽很多,那时候做前端还没多久,很多东西都不知道,别人说用vue开 ...