提交 7ffbb655 编写于 作者: Z zyyang

modified the springboot demo

上级 83ba94b6
...@@ -64,6 +64,8 @@ ...@@ -64,6 +64,8 @@
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.20</version> <version>2.0.20</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/taos-jdbcdriver-2.0.20-dist.jar</systemPath>-->
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -10,4 +10,4 @@ public class SpringbootdemoApplication { ...@@ -10,4 +10,4 @@ public class SpringbootdemoApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args); SpringApplication.run(SpringbootdemoApplication.class, args);
} }
} }
\ No newline at end of file
...@@ -60,7 +60,7 @@ public class WeatherController { ...@@ -60,7 +60,7 @@ public class WeatherController {
} }
@GetMapping("/avg") @GetMapping("/avg")
public Map avg() { public List<Weather> avg() {
return weatherService.avg(); return weatherService.avg();
} }
......
...@@ -24,6 +24,6 @@ public interface WeatherMapper { ...@@ -24,6 +24,6 @@ public interface WeatherMapper {
List<String> getSubTables(); List<String> getSubTables();
Map avg(); List<Weather> avg();
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<resultMap id="BaseResultMap" type="com.taosdata.example.springbootdemo.domain.Weather"> <resultMap id="BaseResultMap" type="com.taosdata.example.springbootdemo.domain.Weather">
<id column="ts" jdbcType="TIMESTAMP" property="ts"/> <id column="ts" jdbcType="TIMESTAMP" property="ts"/>
<result column="temperature" jdbcType="INTEGER" property="temperature"/> <result column="temperature" jdbcType="FLOAT" property="temperature"/>
<result column="humidity" jdbcType="FLOAT" property="humidity"/> <result column="humidity" jdbcType="FLOAT" property="humidity"/>
</resultMap> </resultMap>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</update> </update>
<update id="createSuperTable"> <update id="createSuperTable">
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)
</update> </update>
<update id="createTable" parameterType="com.taosdata.example.springbootdemo.domain.Weather"> <update id="createTable" parameterType="com.taosdata.example.springbootdemo.domain.Weather">
...@@ -47,7 +47,13 @@ ...@@ -47,7 +47,13 @@
select count(*) from test.weather select count(*) from test.weather
</select> </select>
<select id="avg" resultType="map"> <resultMap id="avgResultSet" type="com.taosdata.example.springbootdemo.domain.Weather">
<id column="ts" jdbcType="TIMESTAMP" property="ts" />
<result column="avg(temperature)" jdbcType="FLOAT" property="temperature" />
<result column="avg(humidity)" jdbcType="FLOAT" property="humidity" />
</resultMap>
<select id="avg" resultMap="avgResultSet">
select avg(temperature), avg(humidity)from test.weather interval(1m) select avg(temperature), avg(humidity)from test.weather interval(1m)
</select> </select>
......
...@@ -9,14 +9,14 @@ public class Weather { ...@@ -9,14 +9,14 @@ public class Weather {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Timestamp ts; private Timestamp ts;
private float temperature; private float temperature;
private int humidity; private float humidity;
private String location; private String location;
private int groupId; private int groupId;
public Weather() { public Weather() {
} }
public Weather(Timestamp ts, float temperature, int humidity) { public Weather(Timestamp ts, float temperature, float humidity) {
this.ts = ts; this.ts = ts;
this.temperature = temperature; this.temperature = temperature;
this.humidity = humidity; this.humidity = humidity;
...@@ -38,11 +38,11 @@ public class Weather { ...@@ -38,11 +38,11 @@ public class Weather {
this.temperature = temperature; this.temperature = temperature;
} }
public int getHumidity() { public float getHumidity() {
return humidity; return humidity;
} }
public void setHumidity(int humidity) { public void setHumidity(float humidity) {
this.humidity = humidity; this.humidity = humidity;
} }
......
...@@ -55,7 +55,7 @@ public class WeatherService { ...@@ -55,7 +55,7 @@ public class WeatherService {
return weatherMapper.getSubTables(); return weatherMapper.getSubTables();
} }
public Map avg() { public List<Weather> avg() {
return weatherMapper.avg(); return weatherMapper.avg();
} }
} }
# datasource config - JDBC-JNI # datasource config - JDBC-JNI
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver #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.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.username=root
#spring.datasource.password=taosdata #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.initial-size=5
spring.datasource.druid.min-idle=5 spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=5 spring.datasource.druid.max-active=5
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册