2 Star 13 Fork 10

jwc_gitee/springboot-tdengine-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
jwc- jwc update 93b6e70 2年前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

项目简介

  • springboot-tdengine-demo-mongodb: springboot集成mongodb示例
  • springboot-tdengine-demo-multi-datasource: springboot + MyBatis多数据源示例MySql+TDengine
  • springboot-tdengine-demo-multi-datasource-mybatis-plus: springboot + MyBatis示例-plus + dynamic-datasource多数据源示例MySql+TDengine
  • springboot-tdengine-demo-mybatis: springboot集成TDengine + MyBatis示例
  • springboot-tdengine-demo-mybatis-plus: springboot集成TDengine + MyBatis-Plus示例

TDengine SpringBoot + Mybatis Demo

配置 application.properties

# datasource config - JDBC-RESTful
spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
spring.datasource.url=jdbc:TAOS-RS://你的IP地址:6041/demo?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
spring.datasource.username=root
spring.datasource.password=taosdata

spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=5
spring.datasource.druid.max-wait=30000
spring.datasource.druid.validation-query=select server_status();

#mybatis
#mybatis.mapper-locations=classpath:mapper/*.xml

logging.level.com.taosdata.example.springbootdemo.dao=debug

server.port=8081

主要功能

  • 创建数据库和表
<!-- weatherMapper.xml -->
 <update id="createDB" >
        create database if not exists test;
    </update>

    <update id="createTable" >
        create table if not exists test.weather(ts timestamp, temperature int, humidity float);
    </update>
  • 插入单条记录
<!-- weatherMapper.xml -->
    <insert id="insert" parameterType="Weather" >
        insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
    </insert>
  • 插入多条记录
<!-- weatherMapper.xml -->
<insert id="batchInsert" parameterType="java.util.List" >
    insert into test.weather (ts, temperature, humidity) values
    <foreach separator=" " collection="list" item="weather" index="index" >
        (now + #{index}a, #{weather.temperature}, #{weather.humidity})
    </foreach>
</insert>
  • 分页查询
<!-- weatherMapper.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="WeatherMapper">

    <resultMap id="BaseResultMap" type="Weather">
        <id column="ts" jdbcType="TIMESTAMP" property="ts" />
        <result column="temperature" jdbcType="INTEGER" property="temperature" />
        <result column="humidity" jdbcType="FLOAT" property="humidity" />
    </resultMap>

    <sql id="Base_Column_List">
        ts, temperature, humidity
    </sql>

    <select id="select" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from test.weather
        order by ts desc
        <if test="limit != null">
            limit #{limit,jdbcType=BIGINT}
        </if>
        <if test="offset != null">
            offset #{offset,jdbcType=BIGINT}
        </if>
    </select>
</mapper>

空文件

简介

springboot-tdengine-demo 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/jwc-gitee/springboot-tdengine-demo.git
git@gitee.com:jwc-gitee/springboot-tdengine-demo.git
jwc-gitee
springboot-tdengine-demo
springboot-tdengine-demo
main

搜索帮助