update java code example
This commit is contained in:
parent
b0714e13e9
commit
4af3ab5082
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -6,8 +6,6 @@ import com.taosdata.example.jdbcTemplate.dao.WeatherDao;
|
|||
import com.taosdata.example.jdbcTemplate.domain.Weather;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
@ -20,41 +18,30 @@ public class App {
|
|||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
|
||||
//
|
||||
// ExecuteAsStatement executor = ctx.getBean(ExecuteAsStatement.class);
|
||||
// // drop database
|
||||
// executor.doExecute("drop database if exists test");
|
||||
// // create database
|
||||
// executor.doExecute("create database if not exists test");
|
||||
// //use database
|
||||
// executor.doExecute("use test");
|
||||
// // create table
|
||||
// executor.doExecute("create table if not exists test.weather (ts timestamp, temperature float, humidity int)");
|
||||
//
|
||||
// WeatherDao weatherDao = ctx.getBean(WeatherDao.class);
|
||||
// Weather weather = new Weather(new Timestamp(new Date().getTime()), random.nextFloat() * 50.0f, random.nextInt(100));
|
||||
// // insert rows
|
||||
// int affectedRows = weatherDao.add(weather);
|
||||
// System.out.println("insert success " + affectedRows + " rows.");
|
||||
//
|
||||
// // query for list
|
||||
// int limit = 10, offset = 0;
|
||||
// List<Weather> weatherList = weatherDao.queryForList(limit, offset);
|
||||
// for (Weather w : weatherList) {
|
||||
// System.out.println(w);
|
||||
// }
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
dataSource.setUrl("jdbc:TAOS-RS://vm98:6041/?batchfetch=true&user=root&password=taosdata");
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
|
||||
|
||||
ExecuteAsStatement executor = ctx.getBean(ExecuteAsStatement.class);
|
||||
// drop database
|
||||
executor.doExecute("drop database if exists test");
|
||||
// create database
|
||||
executor.doExecute("create database if not exists test");
|
||||
//use database
|
||||
executor.doExecute("use test");
|
||||
// create table
|
||||
executor.doExecute("create table if not exists test.weather (ts timestamp, temperature float, humidity int)");
|
||||
|
||||
WeatherDao weatherDao = ctx.getBean(WeatherDao.class);
|
||||
Weather weather = new Weather(new Timestamp(new Date().getTime()), random.nextFloat() * 50.0f, random.nextInt(100));
|
||||
// insert rows
|
||||
int affectedRows = weatherDao.add(weather);
|
||||
System.out.println("insert success " + affectedRows + " rows.");
|
||||
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
jdbcTemplate.query("select * from test.meters limit ?, ?",
|
||||
(rs, rowNum) -> rs.getString("ts"), 1, 10)
|
||||
.forEach(System.out::println) ;
|
||||
// query for list
|
||||
int limit = 10, offset = 0;
|
||||
List<Weather> weatherList = weatherDao.queryForList(limit, offset);
|
||||
for (Weather w : weatherList) {
|
||||
System.out.println(w);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<version>3.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<version>3.2.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.taosdata.example.mybatisplusdemo.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -23,10 +22,13 @@ public class MybatisPlusConfig {
|
|||
// }
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||
return interceptor;
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
// return new PaginationInterceptor();
|
||||
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
||||
//TODO: mybatis-plus do not support TDengine, use postgresql Dialect
|
||||
paginationInterceptor.setDialectType("postgresql");
|
||||
|
||||
return paginationInterceptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class TemperatureMapperTest {
|
|||
* **/
|
||||
@Test
|
||||
public void testSelectCount() {
|
||||
long count = mapper.selectCount(null);
|
||||
int count = mapper.selectCount(null);
|
||||
Assert.assertEquals(10, count);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ public class WeatherMapperTest {
|
|||
|
||||
@Test
|
||||
public void testSelectCount() {
|
||||
long count = mapper.selectCount(null);
|
||||
int count = mapper.selectCount(null);
|
||||
// Assert.assertEquals(5, count);
|
||||
System.out.println(count);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue