change
This commit is contained in:
parent
c076d6aeb2
commit
6fecb25da8
|
@ -8,7 +8,7 @@
|
|||
<version>2.2.1.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<groupId>com.taosdata.example</groupId>
|
||||
<artifactId>springbootdemo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>springbootdemo</name>
|
||||
|
@ -63,7 +63,7 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.4</version>
|
||||
<version>2.0.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -71,8 +71,6 @@
|
|||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.17</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -47,7 +47,7 @@ logging.level.com.taosdata.jdbc.springbootdemo.dao=debug
|
|||
* 插入单条记录
|
||||
```xml
|
||||
<!-- weatherMapper.xml -->
|
||||
<insert id="insert" parameterType="com.taosdata.jdbc.springbootdemo.domain.Weather" >
|
||||
<insert id="insert" parameterType="Weather" >
|
||||
insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
|
||||
</insert>
|
||||
```
|
||||
|
@ -67,9 +67,9 @@ logging.level.com.taosdata.jdbc.springbootdemo.dao=debug
|
|||
<?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="com.taosdata.jdbc.springbootdemo.dao.WeatherMapper">
|
||||
<mapper namespace="WeatherMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.taosdata.jdbc.springbootdemo.domain.Weather">
|
||||
<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" />
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package com.taosdata.jdbc.springbootdemo;
|
||||
package com.taosdata.example.springbootdemo;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@MapperScan(basePackages = {"com.taosdata.jdbc.springbootdemo.dao"})
|
||||
@MapperScan(basePackages = {"com.taosdata.example.springbootdemo.dao"})
|
||||
@SpringBootApplication
|
||||
public class cd {
|
||||
|
||||
public class SpringbootdemoApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringbootdemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.taosdata.jdbc.springbootdemo.controller;
|
||||
package com.taosdata.example.springbootdemo.controller;
|
||||
|
||||
import com.taosdata.jdbc.springbootdemo.domain.Weather;
|
||||
import com.taosdata.jdbc.springbootdemo.service.WeatherService;
|
||||
import com.taosdata.example.springbootdemo.domain.Weather;
|
||||
import com.taosdata.example.springbootdemo.service.WeatherService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.taosdata.jdbc.springbootdemo.dao;
|
||||
package com.taosdata.example.springbootdemo.dao;
|
||||
|
||||
import com.taosdata.jdbc.springbootdemo.domain.Weather;
|
||||
import com.taosdata.example.springbootdemo.domain.Weather;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
|
@ -1,9 +1,9 @@
|
|||
<?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="com.taosdata.jdbc.springbootdemo.dao.WeatherMapper">
|
||||
<mapper namespace="com.taosdata.example.springbootdemo.dao.WeatherMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.taosdata.jdbc.springbootdemo.domain.Weather">
|
||||
<resultMap id="BaseResultMap" type="com.taosdata.example.springbootdemo.domain.Weather">
|
||||
<id column="ts" jdbcType="TIMESTAMP" property="ts" />
|
||||
<result column="temperature" jdbcType="INTEGER" property="temperature" />
|
||||
<result column="humidity" jdbcType="FLOAT" property="humidity" />
|
||||
|
@ -34,7 +34,7 @@
|
|||
</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.taosdata.jdbc.springbootdemo.domain.Weather" >
|
||||
<insert id="insert" parameterType="com.taosdata.example.springbootdemo.domain.Weather" >
|
||||
insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
|
||||
</insert>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.taosdata.jdbc.springbootdemo.domain;
|
||||
package com.taosdata.example.springbootdemo.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.taosdata.jdbc.springbootdemo.service;
|
||||
package com.taosdata.example.springbootdemo.service;
|
||||
|
||||
import com.taosdata.jdbc.springbootdemo.dao.WeatherMapper;
|
||||
import com.taosdata.jdbc.springbootdemo.domain.Weather;
|
||||
import com.taosdata.example.springbootdemo.dao.WeatherMapper;
|
||||
import com.taosdata.example.springbootdemo.domain.Weather;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.controller;
|
||||
|
||||
|
||||
import com.taosdata.jdbc.springbootdemo.domain.Rainfall;
|
||||
import com.taosdata.jdbc.springbootdemo.service.RainStationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/rainstation")
|
||||
public class RainStationController {
|
||||
|
||||
@Autowired
|
||||
private RainStationService service;
|
||||
|
||||
@GetMapping("/init")
|
||||
public boolean init() {
|
||||
service.init();
|
||||
service.createTable();
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
public int insert(@RequestBody Rainfall rainfall){
|
||||
return service.insert(rainfall);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.dao;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface DatabaseMapper {
|
||||
|
||||
int createDatabase(String dbname);
|
||||
|
||||
int dropDatabase(String dbname);
|
||||
|
||||
int creatDatabaseWithParameters(Map<String,String> map);
|
||||
|
||||
int useDatabase(String dbname);
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?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="com.taosdata.jdbc.springbootdemo.dao.DatabaseMapper">
|
||||
|
||||
<update id="createDatabase" parameterType="java.lang.String">
|
||||
create database if not exists ${dbname}
|
||||
</update>
|
||||
|
||||
<update id="dropDatabase" parameterType="java.lang.String">
|
||||
DROP database if exists ${dbname}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="creatDatabaseWithParameters" parameterType="map">
|
||||
CREATE database if not EXISTS ${dbname}
|
||||
<if test="keep != null">
|
||||
KEEP ${keep}
|
||||
</if>
|
||||
<if test="days != null">
|
||||
DAYS ${days}
|
||||
</if>
|
||||
<if test="replica != null">
|
||||
REPLICA ${replica}
|
||||
</if>
|
||||
<if test="cache != null">
|
||||
cache ${cache}
|
||||
</if>
|
||||
<if test="blocks != null">
|
||||
blocks ${blocks}
|
||||
</if>
|
||||
<if test="minrows != null">
|
||||
minrows ${minrows}
|
||||
</if>
|
||||
<if test="maxrows != null">
|
||||
maxrows ${maxrows}
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<update id="useDatabase" parameterType="java.lang.String">
|
||||
use ${dbname}
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -1,9 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.dao;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface RainfallMapper {
|
||||
|
||||
|
||||
int save(Map<String, Object> map);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?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="com.taosdata.jdbc.springbootdemo.dao.RainfallMapper">
|
||||
|
||||
<insert id="save" parameterType="map">
|
||||
INSERT INTO ${table} using ${dbname}.${stable} tags(#{values.station_code}, #{values.station_name}) (ts, name, code, rainfall) values (#{values.ts}, #{values.name}, #{values.code}, #{values.rainfall})
|
||||
</insert>
|
||||
|
||||
|
||||
</mapper>
|
|
@ -1,8 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.dao;
|
||||
|
||||
import com.taosdata.jdbc.springbootdemo.domain.TableMetadata;
|
||||
|
||||
public interface TableMapper {
|
||||
|
||||
boolean createSTable(TableMetadata tableMetadata);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?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="com.taosdata.jdbc.springbootdemo.dao.TableMapper">
|
||||
|
||||
<update id="createSTable" parameterType="com.taosdata.jdbc.springbootdemo.domain.TableMetadata">
|
||||
create table if not exists ${dbname}.${tablename}
|
||||
<foreach collection="fields" item="field" index="index" open="(" close=")" separator=",">
|
||||
${field.name} ${field.type}
|
||||
</foreach>
|
||||
TAGS
|
||||
<foreach collection="tags" item="tag" index="index" open="(" close=")" separator=",">
|
||||
${tag.name} ${tag.type}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="dropTable" parameterType="java.lang.String">
|
||||
drop ${tablename}
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -1,28 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.domain;
|
||||
|
||||
public class FieldMetadata {
|
||||
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
public FieldMetadata(String name, String type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class Rainfall {
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS",timezone = "GMT+8")
|
||||
private Timestamp ts;
|
||||
private String name;
|
||||
private String code;
|
||||
private float rainfall;
|
||||
private String station_code;
|
||||
private String station_name;
|
||||
|
||||
public Timestamp getTs() {
|
||||
return ts;
|
||||
}
|
||||
|
||||
public void setTs(Timestamp ts) {
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public float getRainfall() {
|
||||
return rainfall;
|
||||
}
|
||||
|
||||
public void setRainfall(float rainfall) {
|
||||
this.rainfall = rainfall;
|
||||
}
|
||||
|
||||
public String getStation_code() {
|
||||
return station_code;
|
||||
}
|
||||
|
||||
public void setStation_code(String station_code) {
|
||||
this.station_code = station_code;
|
||||
}
|
||||
|
||||
public String getStation_name() {
|
||||
return station_name;
|
||||
}
|
||||
|
||||
public void setStation_name(String station_name) {
|
||||
this.station_name = station_name;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TableMetadata {
|
||||
|
||||
private String dbname;
|
||||
private String tablename;
|
||||
private List<FieldMetadata> fields;
|
||||
private List<TagMetadata> tags;
|
||||
|
||||
public String getDbname() {
|
||||
return dbname;
|
||||
}
|
||||
|
||||
public void setDbname(String dbname) {
|
||||
this.dbname = dbname;
|
||||
}
|
||||
|
||||
public String getTablename() {
|
||||
return tablename;
|
||||
}
|
||||
|
||||
public void setTablename(String tablename) {
|
||||
this.tablename = tablename;
|
||||
}
|
||||
|
||||
public List<FieldMetadata> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(List<FieldMetadata> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<TagMetadata> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<TagMetadata> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.domain;
|
||||
|
||||
public class TagMetadata {
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
public TagMetadata(String name, String type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo.service;
|
||||
|
||||
import com.taosdata.jdbc.springbootdemo.dao.DatabaseMapper;
|
||||
import com.taosdata.jdbc.springbootdemo.dao.RainfallMapper;
|
||||
import com.taosdata.jdbc.springbootdemo.dao.TableMapper;
|
||||
import com.taosdata.jdbc.springbootdemo.domain.FieldMetadata;
|
||||
import com.taosdata.jdbc.springbootdemo.domain.Rainfall;
|
||||
import com.taosdata.jdbc.springbootdemo.domain.TableMetadata;
|
||||
import com.taosdata.jdbc.springbootdemo.domain.TagMetadata;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class RainStationService {
|
||||
|
||||
@Autowired
|
||||
private DatabaseMapper databaseMapper;
|
||||
@Autowired
|
||||
private TableMapper tableMapper;
|
||||
@Autowired
|
||||
private RainfallMapper rainfallMapper;
|
||||
|
||||
public boolean init() {
|
||||
databaseMapper.dropDatabase("rainstation");
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("dbname", "rainstation");
|
||||
map.put("keep", "36500");
|
||||
map.put("days", "30");
|
||||
map.put("blocks", "4");
|
||||
databaseMapper.creatDatabaseWithParameters(map);
|
||||
|
||||
databaseMapper.useDatabase("rainstation");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean createTable() {
|
||||
TableMetadata tableMetadata = new TableMetadata();
|
||||
tableMetadata.setDbname("rainstation");
|
||||
tableMetadata.setTablename("monitoring");
|
||||
|
||||
List<FieldMetadata> fields = new ArrayList<>();
|
||||
fields.add(new FieldMetadata("ts", "timestamp"));
|
||||
fields.add(new FieldMetadata("name", "NCHAR(10)"));
|
||||
fields.add(new FieldMetadata("code", " BINARY(8)"));
|
||||
fields.add(new FieldMetadata("rainfall", "float"));
|
||||
tableMetadata.setFields(fields);
|
||||
|
||||
List<TagMetadata> tags = new ArrayList<>();
|
||||
tags.add(new TagMetadata("station_code", "BINARY(8)"));
|
||||
tags.add(new TagMetadata("station_name", "NCHAR(10)"));
|
||||
tableMetadata.setTags(tags);
|
||||
|
||||
tableMapper.createSTable(tableMetadata);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int insert(Rainfall rainfall) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("dbname", "rainstation");
|
||||
map.put("table", "S_53646");
|
||||
map.put("stable", "monitoring");
|
||||
map.put("values", rainfall);
|
||||
return rainfallMapper.save(map);
|
||||
}
|
||||
}
|
|
@ -1,24 +1,18 @@
|
|||
# datasource config
|
||||
# datasource config - JDBC-JNI
|
||||
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
|
||||
spring.datasource.url=jdbc:TAOS://localhost:6030/log
|
||||
spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=taosdata
|
||||
|
||||
# datasource config - JDBC-RESTful
|
||||
#spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
|
||||
#spring.datasource.url=jdbc:TAOS-RS://master:6041/test?user=root&password=taosdata
|
||||
|
||||
spring.datasource.druid.initial-size=5
|
||||
spring.datasource.druid.min-idle=5
|
||||
spring.datasource.druid.max-active=5
|
||||
# max wait time for get connection, ms
|
||||
spring.datasource.druid.max-wait=60000
|
||||
|
||||
spring.datasource.druid.max-wait=30000
|
||||
spring.datasource.druid.validation-query=select server_status();
|
||||
spring.datasource.druid.validation-query-timeout=5000
|
||||
spring.datasource.druid.test-on-borrow=false
|
||||
spring.datasource.druid.test-on-return=false
|
||||
spring.datasource.druid.test-while-idle=true
|
||||
spring.datasource.druid.time-between-eviction-runs-millis=60000
|
||||
spring.datasource.druid.min-evictable-idle-time-millis=600000
|
||||
spring.datasource.druid.max-evictable-idle-time-millis=900000
|
||||
|
||||
|
||||
#mybatis
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.taosdata.jdbc.springbootdemo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringbootdemoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue