From 7ffbb65588a312a43c6e8121d59a510ffa9a1112 Mon Sep 17 00:00:00 2001 From: zyyang Date: Fri, 5 Mar 2021 15:21:23 +0800 Subject: [PATCH] modified the springboot demo --- tests/examples/JDBC/springbootdemo/pom.xml | 2 ++ .../SpringbootdemoApplication.java | 2 +- .../controller/WeatherController.java | 2 +- .../springbootdemo/dao/WeatherMapper.java | 2 +- .../example/springbootdemo/dao/WeatherMapper.xml | 12 +++++++++--- .../example/springbootdemo/domain/Weather.java | 8 ++++---- .../springbootdemo/service/WeatherService.java | 2 +- .../src/main/resources/application.properties | 16 ++++++++-------- 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/tests/examples/JDBC/springbootdemo/pom.xml b/tests/examples/JDBC/springbootdemo/pom.xml index 4b7272323d..bd5f7efbc0 100644 --- a/tests/examples/JDBC/springbootdemo/pom.xml +++ b/tests/examples/JDBC/springbootdemo/pom.xml @@ -64,6 +64,8 @@ com.taosdata.jdbc taos-jdbcdriver 2.0.20 + + diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java index 8066126d62..8f30c29946 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java @@ -10,4 +10,4 @@ public class SpringbootdemoApplication { public static void main(String[] args) { SpringApplication.run(SpringbootdemoApplication.class, args); } -} +} \ No newline at end of file diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java index 5871d80afe..c153e27701 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java @@ -60,7 +60,7 @@ public class WeatherController { } @GetMapping("/avg") - public Map avg() { + public List avg() { return weatherService.avg(); } diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java index 6cb290bc38..ad6733558a 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java @@ -24,6 +24,6 @@ public interface WeatherMapper { List getSubTables(); - Map avg(); + List avg(); } diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml index b4a36d0e19..2d3e054065 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml @@ -5,7 +5,7 @@ - + @@ -18,7 +18,7 @@ - create table if not exists test.weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int) + create table if not exists test.weather(ts timestamp, temperature float, humidity float) tags(location nchar(64), groupId int) @@ -47,7 +47,13 @@ select count(*) from test.weather - select avg(temperature), avg(humidity)from test.weather interval(1m) diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java index c57eb26ca9..255b2cdca9 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java @@ -9,14 +9,14 @@ public class Weather { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8") private Timestamp ts; private float temperature; - private int humidity; + private float humidity; private String location; private int groupId; public Weather() { } - public Weather(Timestamp ts, float temperature, int humidity) { + public Weather(Timestamp ts, float temperature, float humidity) { this.ts = ts; this.temperature = temperature; this.humidity = humidity; @@ -38,11 +38,11 @@ public class Weather { this.temperature = temperature; } - public int getHumidity() { + public float getHumidity() { return humidity; } - public void setHumidity(int humidity) { + public void setHumidity(float humidity) { this.humidity = humidity; } diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java index dfd7ce23fd..0aef828e1c 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java @@ -55,7 +55,7 @@ public class WeatherService { return weatherMapper.getSubTables(); } - public Map avg() { + public List avg() { return weatherMapper.avg(); } } diff --git a/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties b/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties index 6b1689bb3e..4d7e64d105 100644 --- a/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties +++ b/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties @@ -1,15 +1,15 @@ # datasource config - JDBC-JNI -spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver -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?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8 +#spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver +#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?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 -- GitLab