提交 b82a1c71 编写于 作者: Z zyyang

add count and select tbname SQL test in springbootdemo

上级 ecf5daae
...@@ -59,4 +59,14 @@ public class WeatherController { ...@@ -59,4 +59,14 @@ public class WeatherController {
return weatherService.save(weatherList); return weatherService.save(weatherList);
} }
@GetMapping("/count")
public int count() {
return weatherService.count();
}
@GetMapping("/subTables")
public List<String> getSubTables() {
return weatherService.getSubTables();
}
} }
...@@ -11,9 +11,13 @@ public interface WeatherMapper { ...@@ -11,9 +11,13 @@ public interface WeatherMapper {
int batchInsert(List<Weather> weatherList); int batchInsert(List<Weather> weatherList);
List<Weather> select(@Param("limit") Long limit, @Param("offset")Long offset); List<Weather> select(@Param("limit") Long limit, @Param("offset") Long offset);
void createDB(); void createDB();
void createTable(); void createTable();
int count();
List<String> getSubTables();
} }
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
<mapper namespace="com.taosdata.example.springbootdemo.dao.WeatherMapper"> <mapper namespace="com.taosdata.example.springbootdemo.dao.WeatherMapper">
<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="INTEGER" property="temperature"/>
<result column="humidity" jdbcType="FLOAT" property="humidity" /> <result column="humidity" jdbcType="FLOAT" property="humidity"/>
</resultMap> </resultMap>
<update id="createDB" > <update id="createDB">
create database if not exists test; create database if not exists test;
</update> </update>
<update id="createTable" > <update id="createTable">
create table if not exists test.weather(ts timestamp, temperature int, humidity float); create table if not exists test.weather(ts timestamp, temperature int, humidity float);
</update> </update>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<select id="select" resultMap="BaseResultMap"> <select id="select" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from test.weather from test.weather
order by ts desc order by ts desc
<if test="limit != null"> <if test="limit != null">
...@@ -34,16 +34,23 @@ ...@@ -34,16 +34,23 @@
</if> </if>
</select> </select>
<insert id="insert" parameterType="com.taosdata.example.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 into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
</insert> </insert>
<insert id="batchInsert" parameterType="java.util.List" > <insert id="batchInsert" parameterType="java.util.List">
insert into test.weather (ts, temperature, humidity) values insert into test.weather (ts, temperature, humidity) values
<foreach separator=" " collection="list" item="weather" index="index" > <foreach separator=" " collection="list" item="weather" index="index">
(now + #{index}a, #{weather.temperature}, #{weather.humidity}) (now + #{index}a, #{weather.temperature}, #{weather.humidity})
</foreach> </foreach>
</insert> </insert>
<select id="getSubTables">
select tbname from test.weather
</select>
<select id="count">
select count(*) from test.weather;
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -35,4 +35,12 @@ public class WeatherService { ...@@ -35,4 +35,12 @@ public class WeatherService {
return weatherMapper.batchInsert(weatherList); return weatherMapper.batchInsert(weatherList);
} }
public int count() {
return weatherMapper.count();
}
public List<String> getSubTables() {
return weatherMapper.getSubTables();
}
} }
# 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?user=root&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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册