SpringBoot+Mybatis整合TDengine数据库的Demo

记录一下使用SpringBoot+Mybatis整合TDengine数据库的Demo,支持分页返回查询数据

demo代码

分页查询
myw
myw
模拟插入数据 批量插入和单条插入数据
myw
TDengine Database 数据库查询数据

myw

在使用之前,需要先安装好TDengine Datavase

Ubuntu系统安装TDengine Database

Centos系统安装TDengine Database

首先进入TDengine数据库,创建数据库和超级表,这里使用的是按照设备的imei来存储温湿度值(物联网方式)

[root@192 ~]# taos
Welcome to the TDengine Command Line Interface, Client Version:3.2.3.0
Copyright (c) 2023 by TDengine, all rights reserved.

  ********************************  Tab Completion  ************************************
  *   The TDengine CLI supports tab completion for a variety of items,                 *
  *   including database names, table names, function names and keywords.              *
  *   The full list of shortcut keys is as follows:                                    *
  *    [ TAB ]        ......  complete the current word                                *
  *                   ......  if used on a blank line, display all supported commands  *
  *    [ Ctrl + A ]   ......  move cursor to the st[A]rt of the line                   *
  *    [ Ctrl + E ]   ......  move cursor to the [E]nd of the line                     *
  *    [ Ctrl + W ]   ......  move cursor to the middle of the line                    *
  *    [ Ctrl + L ]   ......  clear the entire screen                                  *
  *    [ Ctrl + K ]   ......  clear the screen after the cursor                        *
  *    [ Ctrl + U ]   ......  clear the screen before the cursor                       *
  **************************************************************************************

Server is Community Edition.

taos> 

创建数据库 两种格式,其中第二种支持不存在才创建

create database td_device_log;
create database if not exists td_device_log;
taos> create database td_device_log;
Create OK, 0 row(s) affected (0.959227s)

taos> create database if not exists td_device_log;
Create OK, 0 row(s) affected (0.002038s)

创建超级表,时间戳 imei唯一的编码(可看一类数据的或者某个设备的成唯一ID),temp和hum是温湿度的字段

taos> use td_device_log;
Database changed.

taos> CREATE STABLE device_env_imei(time_stamp TIMESTAMP, imei varchar(64), temp varchar(64), hum varchar(64)) TAGS (imei_point varchar(64));
Create OK, 0 row(s) affected (0.014501s)

taos> 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>boot.example.mybatis.tdengine</groupId>
    <artifactId>boot-example-mybatis-tdengine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>boot-example-mybatis-tdengine</name>
    <description>boot-example-mybatis-tdengine</description>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.taosdata.jdbc</groupId>
            <artifactId>taos-jdbcdriver</artifactId>
            <version>3.2.8</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值