change
This commit is contained in:
parent
2a683c5b9c
commit
0b5729fbf7
|
@ -48,17 +48,6 @@ public class WeatherController {
|
|||
return weatherService.save(temperature, humidity);
|
||||
}
|
||||
|
||||
/**
|
||||
* upload multi weather info
|
||||
*
|
||||
* @param weatherList
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/batch")
|
||||
public int batchSaveWeather(@RequestBody List<Weather> weatherList) {
|
||||
return weatherService.save(weatherList);
|
||||
}
|
||||
|
||||
@GetMapping("/count")
|
||||
public int count() {
|
||||
return weatherService.count();
|
||||
|
|
|
@ -11,14 +11,12 @@ public interface WeatherMapper {
|
|||
|
||||
void createSuperTable();
|
||||
|
||||
void createTable();
|
||||
void createTable(Weather weather);
|
||||
|
||||
List<Weather> select(@Param("limit") Long limit, @Param("offset") Long offset);
|
||||
|
||||
int insert(Weather weather);
|
||||
|
||||
int batchInsert(List<Weather> weatherList);
|
||||
|
||||
int count();
|
||||
|
||||
List<String> getSubTables();
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
</resultMap>
|
||||
|
||||
<update id="createDB">
|
||||
create database if not exists test;
|
||||
create database if not exists test
|
||||
</update>
|
||||
|
||||
<update id="createSuperTable">
|
||||
|
@ -32,14 +32,7 @@
|
|||
</select>
|
||||
|
||||
<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>
|
||||
|
||||
<insert id="batchInsert" parameterType="java.util.List">
|
||||
insert into test.weather (ts, temperature, humidity) values
|
||||
<foreach separator=" " collection="list" item="weather" index="index">
|
||||
(now + #{index}a, #{weather.temperature}, #{weather.humidity})
|
||||
</foreach>
|
||||
insert into test.t#{groupId} (ts, temperature, humidity) values (#{ts}, #{temperature}, #{humidity})
|
||||
</insert>
|
||||
|
||||
<select id="getSubTables">
|
||||
|
|
|
@ -15,15 +15,19 @@ public class WeatherService {
|
|||
@Autowired
|
||||
private WeatherMapper weatherMapper;
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
private String[] locations = {"北京", "上海", "广州", "深圳", "天津"};
|
||||
|
||||
public int init() {
|
||||
weatherMapper.createDB();
|
||||
weatherMapper.createSuperTable();
|
||||
weatherMapper.createTable();
|
||||
long ts = System.currentTimeMillis();
|
||||
int count = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
count += weatherMapper.insert(new Weather(new Timestamp(ts + (1000 * i)), 30 * random.nextFloat(), random.nextInt(100)));
|
||||
Weather weather = new Weather(new Timestamp(ts + (1000 * i)), 30 * random.nextFloat(), random.nextInt(100));
|
||||
weather.setLocation(locations[random.nextInt(locations.length)]);
|
||||
weather.setGroupId(i % locations.length);
|
||||
weatherMapper.createTable(weather);
|
||||
count += weatherMapper.insert(weather);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -40,10 +44,6 @@ public class WeatherService {
|
|||
return weatherMapper.insert(weather);
|
||||
}
|
||||
|
||||
public int save(List<Weather> weatherList) {
|
||||
return weatherMapper.batchInsert(weatherList);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return weatherMapper.count();
|
||||
}
|
||||
|
|
|
@ -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://localhost: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
|
||||
|
|
Loading…
Reference in New Issue