diff --git a/tests/examples/JDBC/springbootdemo/pom.xml b/tests/examples/JDBC/springbootdemo/pom.xml
index 5f31d36d6ecff11ff73425ee5c806c27d329e9ee..881ea0d6bf485891a29427853bd1bbf9b294c2d8 100644
--- a/tests/examples/JDBC/springbootdemo/pom.xml
+++ b/tests/examples/JDBC/springbootdemo/pom.xml
@@ -63,7 +63,7 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.2
+ 2.0.4
@@ -76,6 +76,24 @@
+
+
+ src/main/resources
+
+ **/*.properties
+ **/*.xml
+
+ true
+
+
+ src/main/java
+
+ **/*.properties
+ **/*.xml
+
+
+
+
org.springframework.boot
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/RainStationController.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/RainStationController.java
new file mode 100644
index 0000000000000000000000000000000000000000..844ac21bb8855de06edcc586deb713bcad686385
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/RainStationController.java
@@ -0,0 +1,28 @@
+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);
+ }
+
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController.java
index 9123abd97b82fe1d4267c7341f3ea87bd5127caa..56a58fbb4d9a783a34989eae00369ff7b307acaf 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController.java
@@ -16,43 +16,47 @@ public class WeatherController {
/**
* create database and table
+ *
* @return
*/
@GetMapping("/init")
- public boolean init(){
+ public boolean init() {
return weatherService.init();
}
/**
* Pagination Query
+ *
* @param limit
* @param offset
* @return
*/
@GetMapping("/{limit}/{offset}")
- public List queryWeather(@PathVariable Long limit, @PathVariable Long offset){
+ public List queryWeather(@PathVariable Long limit, @PathVariable Long offset) {
return weatherService.query(limit, offset);
}
/**
* upload single weather info
+ *
* @param temperature
* @param humidity
* @return
*/
@PostMapping("/{temperature}/{humidity}")
- public int saveWeather(@PathVariable int temperature, @PathVariable float humidity){
+ public int saveWeather(@PathVariable int temperature, @PathVariable float humidity) {
return weatherService.save(temperature, humidity);
}
/**
* upload multi weather info
+ *
* @param weatherList
* @return
*/
@PostMapping("/batch")
- public int batchSaveWeather(@RequestBody List weatherList){
+ public int batchSaveWeather(@RequestBody List weatherList) {
return weatherService.save(weatherList);
}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/DatabaseMapper.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/DatabaseMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..a9266acb3028c453062ce6e56ccade53c405f742
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/DatabaseMapper.java
@@ -0,0 +1,15 @@
+package com.taosdata.jdbc.springbootdemo.dao;
+
+import java.util.Map;
+
+public interface DatabaseMapper {
+
+ int createDatabase(String dbname);
+
+ int dropDatabase(String dbname);
+
+ int creatDatabaseWithParameters(Map map);
+
+ int useDatabase(String dbname);
+
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/DatabaseMapper.xml b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/DatabaseMapper.xml
new file mode 100644
index 0000000000000000000000000000000000000000..329f75b582a276bed522e671d0c9f868b837c172
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/DatabaseMapper.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+ create database if not exists ${dbname}
+
+
+
+ DROP database if exists ${dbname}
+
+
+
+
+ CREATE database if not EXISTS ${dbname}
+
+ KEEP ${keep}
+
+
+ DAYS ${days}
+
+
+ REPLICA ${replica}
+
+
+ cache ${cache}
+
+
+ blocks ${blocks}
+
+
+ minrows ${minrows}
+
+
+ maxrows ${maxrows}
+
+
+
+
+ use ${dbname}
+
+
+
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/RainfallMapper.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/RainfallMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..f0efbf40ba477d9b8f410e0806be38701d274394
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/RainfallMapper.java
@@ -0,0 +1,9 @@
+package com.taosdata.jdbc.springbootdemo.dao;
+
+import java.util.Map;
+
+public interface RainfallMapper {
+
+
+ int save(Map map);
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/RainfallMapper.xml b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/RainfallMapper.xml
new file mode 100644
index 0000000000000000000000000000000000000000..319b4f397434f1b7623c31250c8ba798c0499d86
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/RainfallMapper.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+ 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})
+
+
+
+
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/TableMapper.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/TableMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..7601bf974c7c727b2a46171b145bdcec662dc258
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/TableMapper.java
@@ -0,0 +1,8 @@
+package com.taosdata.jdbc.springbootdemo.dao;
+
+import com.taosdata.jdbc.springbootdemo.domain.TableMetadata;
+
+public interface TableMapper {
+
+ boolean createSTable(TableMetadata tableMetadata);
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/TableMapper.xml b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/TableMapper.xml
new file mode 100644
index 0000000000000000000000000000000000000000..5a272eadb4abd7637735a834ec445c822073486f
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/TableMapper.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+ create table if not exists ${dbname}.${tablename}
+
+ ${field.name} ${field.type}
+
+ TAGS
+
+ ${tag.name} ${tag.type}
+
+
+
+
+ drop ${tablename}
+
+
+
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/resources/mapper/WeatherMapper.xml b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/WeatherMapper.xml
similarity index 100%
rename from tests/examples/JDBC/springbootdemo/src/main/resources/mapper/WeatherMapper.xml
rename to tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/WeatherMapper.xml
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/FieldMetadata.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/FieldMetadata.java
new file mode 100644
index 0000000000000000000000000000000000000000..619b5a303d715132d6a428770a27d069a9b9dcaa
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/FieldMetadata.java
@@ -0,0 +1,28 @@
+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;
+ }
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Rainfall.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Rainfall.java
new file mode 100644
index 0000000000000000000000000000000000000000..93e199d7e66582e7f8d771994b358a2c58f5dae2
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Rainfall.java
@@ -0,0 +1,64 @@
+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;
+ }
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/TableMetadata.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/TableMetadata.java
new file mode 100644
index 0000000000000000000000000000000000000000..74bb434f08484af6c244dd884570c974ab93e634
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/TableMetadata.java
@@ -0,0 +1,43 @@
+package com.taosdata.jdbc.springbootdemo.domain;
+
+import java.util.List;
+
+public class TableMetadata {
+
+ private String dbname;
+ private String tablename;
+ private List fields;
+ private List 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 getFields() {
+ return fields;
+ }
+
+ public void setFields(List fields) {
+ this.fields = fields;
+ }
+
+ public List getTags() {
+ return tags;
+ }
+
+ public void setTags(List tags) {
+ this.tags = tags;
+ }
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/TagMetadata.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/TagMetadata.java
new file mode 100644
index 0000000000000000000000000000000000000000..755ecc0075506c4ba2c99eafa47593a69a50bd84
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/TagMetadata.java
@@ -0,0 +1,27 @@
+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;
+ }
+}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather.java
index 9547a8a89bf4aaff73696091e54f5bb460dcb796..cd7de447eade4a126c86c38c703d6a4de444c557 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather.java
@@ -1,9 +1,12 @@
package com.taosdata.jdbc.springbootdemo.domain;
+import com.fasterxml.jackson.annotation.JsonFormat;
+
import java.sql.Timestamp;
public class Weather {
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS",timezone = "GMT+8")
private Timestamp ts;
private int temperature;
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/RainStationService.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/RainStationService.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ea63c1760d4aef9e11a076eaff0c19df3a3a73c
--- /dev/null
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/RainStationService.java
@@ -0,0 +1,72 @@
+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 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 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 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 map = new HashMap<>();
+ map.put("dbname", "rainstation");
+ map.put("table", "S_53646");
+ map.put("stable", "monitoring");
+ map.put("values", rainfall);
+ return rainfallMapper.save(map);
+ }
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService.java
index 396d70bf9246bfd7e293cccec5b00f2d4aac4963..b950a9a4e42e306320415c7be556ba78c2f25a27 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService.java
@@ -14,10 +14,8 @@ public class WeatherService {
private WeatherMapper weatherMapper;
public boolean init() {
-
weatherMapper.createDB();
weatherMapper.createTable();
-
return true;
}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties b/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
index 926559a90c7ac4bdfbcc2cb0d086154ec0c9cd7f..683884fcdd852fd1a72c685b40c6a8517ed92ff4 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
+++ b/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
@@ -1,6 +1,6 @@
# datasource config
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
-spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/log
+spring.datasource.url=jdbc:TAOS://localhost:6030/log
spring.datasource.username=root
spring.datasource.password=taosdata