提交 0b5729fb 编写于 作者: Z zyyang

change

上级 2a683c5b
...@@ -48,17 +48,6 @@ public class WeatherController { ...@@ -48,17 +48,6 @@ public class WeatherController {
return weatherService.save(temperature, humidity); 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") @GetMapping("/count")
public int count() { public int count() {
return weatherService.count(); return weatherService.count();
......
...@@ -11,14 +11,12 @@ public interface WeatherMapper { ...@@ -11,14 +11,12 @@ public interface WeatherMapper {
void createSuperTable(); void createSuperTable();
void createTable(); void createTable(Weather weather);
List<Weather> select(@Param("limit") Long limit, @Param("offset") Long offset); List<Weather> select(@Param("limit") Long limit, @Param("offset") Long offset);
int insert(Weather weather); int insert(Weather weather);
int batchInsert(List<Weather> weatherList);
int count(); int count();
List<String> getSubTables(); List<String> getSubTables();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</resultMap> </resultMap>
<update id="createDB"> <update id="createDB">
create database if not exists test; create database if not exists test
</update> </update>
<update id="createSuperTable"> <update id="createSuperTable">
...@@ -32,14 +32,7 @@ ...@@ -32,14 +32,7 @@
</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.t#{groupId} (ts, temperature, humidity) values (#{ts}, #{temperature}, #{humidity})
</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> </insert>
<select id="getSubTables"> <select id="getSubTables">
......
...@@ -15,15 +15,19 @@ public class WeatherService { ...@@ -15,15 +15,19 @@ public class WeatherService {
@Autowired @Autowired
private WeatherMapper weatherMapper; private WeatherMapper weatherMapper;
private Random random = new Random(System.currentTimeMillis()); private Random random = new Random(System.currentTimeMillis());
private String[] locations = {"北京", "上海", "广州", "深圳", "天津"};
public int init() { public int init() {
weatherMapper.createDB(); weatherMapper.createDB();
weatherMapper.createSuperTable(); weatherMapper.createSuperTable();
weatherMapper.createTable();
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
int count = 0; int count = 0;
for (int i = 0; i < 10; i++) { 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; return count;
} }
...@@ -40,10 +44,6 @@ public class WeatherService { ...@@ -40,10 +44,6 @@ public class WeatherService {
return weatherMapper.insert(weather); return weatherMapper.insert(weather);
} }
public int save(List<Weather> weatherList) {
return weatherMapper.batchInsert(weatherList);
}
public int count() { public int count() {
return weatherMapper.count(); return weatherMapper.count();
} }
......
# 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://localhost: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.
先完成此消息的编辑!
想要评论请 注册