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. react 学习资料

    react 学习资料 项目 学习资料 react 中文版:https://doc.react-china.org/ react-router https://reacttraining.com/rea ...

  2. Typescript学习总结之模块

    面向对象的特性 模块 模块可以帮助开发者将代码分割为可重用的单元.开发者可以自己决定将模块中的哪些资源(类.方法.变量) 暴露给外部使用,哪些资源只在模块内使用. 如下图, 创建了a.ts 和b.ts ...

  3. chmod命令详解

    Linux chmod命令 Linux/Unix 的文件调用权限分为三级 : 文件拥有者.群组.其他.利用 chmod 可以藉以控制文件如何被他人所调用. 使用权限 : 所有使用者 语法: chmod ...

  4. org.apache.ibatis.binding.BindingException: Invalid bound statement

    idea中出现了这个问题 我的解决方案是: 把mapper映射文件放到资源目录下 然后就行了. 当然,这个具体原因就是:mapper.xml和接口对不上引起的,具体问题还要具体解决 协助博客:http ...

  5. OpenSSL 1.0.0生成p12、jks、crt等格式证书的命令个过程 -参考自http://lavasoft.blog.51cto.com/62575/1104993/

    OpenSSL 1.0.0生成p12.jks.crt等格式证书的命令个过程   此生成的证书可用于浏览器.java.tomcat.c++等.在此备忘!     1.创建根证私钥命令:openssl g ...

  6. 局域网内远程连接OPC配置方法详解

    局域网内远程连接OPC配置方法详解 https://wenku.baidu.com/view/20fb8ea6d1d233d4b14e852458fb770bf78a3bcc.html   OPC服务 ...

  7. Ubuntu 14.10 下连接SuperVessel Cloud

    第一次创建实例后,系统会分配一个VPN用户,用于连接到系统. 官方帮助文档给出了使用方法 Linux VPN 客户端的配置方法 . 安装 VPNC: $ apt-get install vpnc $ ...

  8. flume-sink

    概述 从Flume Agent移除数据并写入到另一个Agent或数据存储或一些其他存储系统的组件被称为sink.Sink不断的轮询channel中的事件且批量的移除它们.这些事件批量写入到存储或索引系 ...

  9. 数组连接a.concat(b),b作为一个整体

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  10. 1127 ZigZagging on a Tree (30 分)

    1127 ZigZagging on a Tree (30 分) Suppose that all the keys in a binary tree are distinct positive in ...