Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c6c7ab3b
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c6c7ab3b
编写于
11月 16, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
5349141d
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
231 addition
and
76 deletion
+231
-76
tests/examples/JDBC/mybatisplus-demo/pom.xml
tests/examples/JDBC/mybatisplus-demo/pom.xml
+18
-0
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java
...ata/example/mybatisplusdemo/config/MybatisPlusConfig.java
+8
-1
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/controller/WeatherController.java
...example/mybatisplusdemo/controller/WeatherController.java
+0
-39
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/domain/Temperature.java
.../taosdata/example/mybatisplusdemo/domain/Temperature.java
+15
-0
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.java
...ata/example/mybatisplusdemo/mapper/TemperatureMapper.java
+15
-0
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.xml
...data/example/mybatisplusdemo/mapper/TemperatureMapper.xml
+22
-0
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapper.java
...aosdata/example/mybatisplusdemo/mapper/WeatherMapper.java
+0
-2
tests/examples/JDBC/mybatisplus-demo/src/main/resources/application.yml
.../JDBC/mybatisplus-demo/src/main/resources/application.yml
+16
-8
tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapperTest.java
...example/mybatisplusdemo/mapper/TemperatureMapperTest.java
+119
-0
tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java
...ata/example/mybatisplusdemo/mapper/WeatherMapperTest.java
+18
-26
未找到文件。
tests/examples/JDBC/mybatisplus-demo/pom.xml
浏览文件 @
c6c7ab3b
...
...
@@ -75,6 +75,24 @@
</dependencies>
<build>
<resources>
<!-- <resource>-->
<!-- <directory>src/main/resources</directory>-->
<!-- <includes>-->
<!-- <include>**/*.properties</include>-->
<!-- <include>**/*.xml</include>-->
<!-- </includes>-->
<!-- <filtering>true</filtering>-->
<!-- </resource>-->
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>
**/*.properties
</include>
<include>
**/*.xml
</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
...
...
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java
浏览文件 @
c6c7ab3b
...
...
@@ -7,6 +7,8 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public
class
MybatisPlusConfig
{
/** mybatis 3.4.1 pagination config start ***/
// @Bean
// public MybatisPlusInterceptor mybatisPlusInterceptor() {
// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
...
...
@@ -21,7 +23,12 @@ public class MybatisPlusConfig {
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
return
new
PaginationInterceptor
();
// return new PaginationInterceptor();
PaginationInterceptor
paginationInterceptor
=
new
PaginationInterceptor
();
//TODO: mybatis-plus do not support TDengine, use mysql Dialect
paginationInterceptor
.
setDialectType
(
"mysql"
);
return
paginationInterceptor
;
}
}
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/controller/WeatherController.java
已删除
100644 → 0
浏览文件 @
5349141d
package
com.taosdata.example.mybatisplusdemo.controller
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.taosdata.example.mybatisplusdemo.domain.Weather
;
import
com.taosdata.example.mybatisplusdemo.mapper.WeatherMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/weathers"
)
public
class
WeatherController
{
@Autowired
private
WeatherMapper
mapper
;
@GetMapping
public
List
<
Weather
>
findAll
()
{
Integer
total
=
mapper
.
selectCount
(
null
);
final
int
pageSize
=
3
;
IPage
<
Weather
>
page
=
new
Page
<>(
1
,
pageSize
);
IPage
<
Weather
>
currentPage
=
mapper
.
selectPage
(
page
,
null
);
System
.
out
.
println
(
"total : "
+
currentPage
.
getTotal
());
System
.
out
.
println
(
"pages : "
+
currentPage
.
getPages
());
// System.out.println("countId : " + currentPage.getCountId());
// System.out.println("maxLimit: " + currentPage.getMaxLimit());
return
currentPage
.
getRecords
();
}
}
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/domain/Temperature.java
0 → 100644
浏览文件 @
c6c7ab3b
package
com.taosdata.example.mybatisplusdemo.domain
;
import
lombok.Data
;
import
java.sql.Timestamp
;
@Data
public
class
Temperature
{
private
Timestamp
ts
;
private
float
temperature
;
private
String
location
;
private
int
tbIndex
;
}
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.java
0 → 100644
浏览文件 @
c6c7ab3b
package
com.taosdata.example.mybatisplusdemo.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.taosdata.example.mybatisplusdemo.domain.Temperature
;
public
interface
TemperatureMapper
extends
BaseMapper
<
Temperature
>
{
int
createSuperTable
();
int
createTable
(
String
tbName
,
String
location
);
void
dropSuperTable
();
int
insertOne
(
Temperature
one
);
}
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.xml
0 → 100644
浏览文件 @
c6c7ab3b
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.taosdata.example.mybatisplusdemo.mapper.TemperatureMapper"
>
<update
id=
"createSuperTable"
>
CREATE TABLE if not exists temperature(ts timestamp, temperature float) tags(location nchar(64), tbIndex int);
</update>
<update
id=
"createTable"
parameterType=
"java.lang.String"
>
create table #{tbname} using temperature tags( #{location} );
</update>
<update
id=
"dropSuperTable"
>
drop table if exists temperature
</update>
<insert
id=
"insertOne"
parameterType=
"com.taosdata.example.mybatisplusdemo.domain.Temperature"
>
insert into t${tbIndex}(ts, temperature) values(ts, temperature)
</insert>
</mapper>
\ No newline at end of file
tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapper.java
浏览文件 @
c6c7ab3b
package
com.taosdata.example.mybatisplusdemo.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.taosdata.example.mybatisplusdemo.domain.Weather
;
public
interface
WeatherMapper
extends
BaseMapper
<
Weather
>
{
...
...
tests/examples/JDBC/mybatisplus-demo/src/main/resources/application.yml
浏览文件 @
c6c7ab3b
spring
:
datasource
:
# driver-class-name:
com.taosdata.jdbc.TSDB
Driver
#
url: jdbc:TAOS://localhost:6030/mp_test
#
user: root
#
password: taosdata
#
charset: UTF-8
#
locale: en_US.UTF-8
# timezone: UTC-8
# driver-class-name:
org.h2.
Driver
#
schema: classpath:db/schema-mysql.sql
#
data: classpath:db/data-mysql.sql
#
url: jdbc:h2:mem:test
#
username: root
#
password: test
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://master:3306/test?useSSL=false
url
:
jdbc:mysql://master:3306/test?useSSL=false
username
:
root
password
:
123456
# driver-class-name: com.taosdata.jdbc.TSDBDriver
# url: jdbc:TAOS://localhost:6030/mp_test
# user: root
# password: taosdata
# charset: UTF-8
# locale: en_US.UTF-8
# timezone: UTC-8
logging
:
level
:
com
:
...
...
tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapperTest.java
0 → 100644
浏览文件 @
c6c7ab3b
package
com.taosdata.example.mybatisplusdemo.mapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.taosdata.example.mybatisplusdemo.domain.Temperature
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.sql.Timestamp
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TemperatureMapperTest
{
private
static
Random
random
=
new
Random
(
System
.
currentTimeMillis
());
private
static
String
[]
locations
=
{
"北京"
,
"上海"
,
"深圳"
,
"广州"
,
"杭州"
};
@Before
public
void
before
()
{
// create table temperature
mapper
.
createSuperTable
();
// create table t_X using temperature
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
mapper
.
createTable
(
"t_"
+
i
,
locations
[
random
.
nextInt
(
locations
.
length
)]);
}
// insert into table
int
affectRows
=
0
;
// insert 10 tables
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
// each table insert 5 rows
for
(
int
j
=
0
;
j
<
5
;
j
++)
{
Temperature
one
=
new
Temperature
();
one
.
setTs
(
new
Timestamp
(
1605024000000
l
));
one
.
setTemperature
(
random
.
nextFloat
()
*
50
);
one
.
setLocation
(
"望京"
);
one
.
setTbIndex
(
i
);
affectRows
+=
mapper
.
insertOne
(
one
);
}
}
Assert
.
assertEquals
(
50
,
affectRows
);
}
@After
public
void
after
()
{
mapper
.
dropSuperTable
();
}
@Autowired
private
TemperatureMapper
mapper
;
@Test
public
void
testSelectList
()
{
List
<
Temperature
>
temperatureList
=
mapper
.
selectList
(
null
);
temperatureList
.
forEach
(
System
.
out
::
println
);
}
@Test
public
void
testInsert
()
{
Temperature
one
=
new
Temperature
();
one
.
setTs
(
new
Timestamp
(
1605024000000
l
));
one
.
setTemperature
(
random
.
nextFloat
()
*
50
);
one
.
setLocation
(
"望京"
);
int
affectRows
=
mapper
.
insertOne
(
one
);
Assert
.
assertEquals
(
1
,
affectRows
);
}
@Test
public
void
testSelectOne
()
{
QueryWrapper
<
Temperature
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"location"
,
"beijing"
);
Temperature
one
=
mapper
.
selectOne
(
wrapper
);
System
.
out
.
println
(
one
);
Assert
.
assertEquals
(
12.22f
,
one
.
getTemperature
(),
0.00f
);
Assert
.
assertEquals
(
"beijing"
,
one
.
getLocation
());
}
@Test
public
void
testSelectByMap
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"location"
,
"beijing"
);
List
<
Temperature
>
temperatures
=
mapper
.
selectByMap
(
map
);
Assert
.
assertEquals
(
1
,
temperatures
.
size
());
}
@Test
public
void
testSelectObjs
()
{
List
<
Object
>
ts
=
mapper
.
selectObjs
(
null
);
System
.
out
.
println
(
ts
);
}
@Test
public
void
testSelectCount
()
{
int
count
=
mapper
.
selectCount
(
null
);
Assert
.
assertEquals
(
5
,
count
);
}
@Test
public
void
testSelectPage
()
{
IPage
page
=
new
Page
(
1
,
2
);
IPage
<
Temperature
>
temperatureIPage
=
mapper
.
selectPage
(
page
,
null
);
System
.
out
.
println
(
"total : "
+
temperatureIPage
.
getTotal
());
System
.
out
.
println
(
"pages : "
+
temperatureIPage
.
getPages
());
for
(
Temperature
temperature
:
temperatureIPage
.
getRecords
())
{
System
.
out
.
println
(
temperature
);
}
}
}
\ No newline at end of file
tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java
浏览文件 @
c6c7ab3b
...
...
@@ -28,19 +28,18 @@ public class WeatherMapperTest {
@Test
public
void
testSelectList
()
{
List
<
Weather
>
weatherList
=
mapper
.
selectList
(
null
);
// Assert.assertEquals(5, weatherList.size());
weatherList
.
forEach
(
System
.
out
::
println
);
List
<
Weather
>
weathers
=
mapper
.
selectList
(
null
);
weathers
.
forEach
(
System
.
out
::
println
);
}
@Test
public
void
testInsert
()
{
Weather
weather
=
new
Weather
();
weather
.
setTs
(
new
Timestamp
(
1605024000000
l
));
weather
.
setTemperature
(
random
.
nextFloat
()
*
50
);
weather
.
setHumidity
(
random
.
nextInt
(
100
));
weather
.
setLocation
(
"望京"
);
int
affectRows
=
mapper
.
insert
(
weather
);
Weather
one
=
new
Weather
();
one
.
setTs
(
new
Timestamp
(
1605024000000
l
));
one
.
setTemperature
(
random
.
nextFloat
()
*
50
);
one
.
setHumidity
(
random
.
nextInt
(
100
));
one
.
setLocation
(
"望京"
);
int
affectRows
=
mapper
.
insert
(
one
);
Assert
.
assertEquals
(
1
,
affectRows
);
}
...
...
@@ -48,11 +47,10 @@ public class WeatherMapperTest {
public
void
testSelectOne
()
{
QueryWrapper
<
Weather
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"location"
,
"beijing"
);
Weather
weather
=
mapper
.
selectOne
(
wrapper
);
System
.
out
.
println
(
weather
);
Assert
.
assertEquals
(
12.22f
,
weather
.
getTemperature
(),
0.00f
);
Assert
.
assertEquals
(
45
,
weather
.
getHumidity
());
Assert
.
assertEquals
(
"beijing"
,
weather
.
getLocation
());
Weather
one
=
mapper
.
selectOne
(
wrapper
);
System
.
out
.
println
(
one
);
Assert
.
assertEquals
(
12.22f
,
one
.
getTemperature
(),
0.00f
);
Assert
.
assertEquals
(
"beijing"
,
one
.
getLocation
());
}
@Test
...
...
@@ -67,30 +65,24 @@ public class WeatherMapperTest {
public
void
testSelectObjs
()
{
List
<
Object
>
ts
=
mapper
.
selectObjs
(
null
);
System
.
out
.
println
(
ts
);
// Assert.assertEquals(5, ts.size());
}
@Test
public
void
testSelectCount
()
{
int
count
=
mapper
.
selectCount
(
null
);
Assert
.
assertEquals
(
5
,
count
);
// Assert.assertEquals(5, count);
System
.
out
.
println
(
count
);
}
@Test
public
void
testSelectPage
()
{
// Page<Weather> page = new Page<>(1, 2);
IPage
page
=
new
Page
(
1
,
2
);
IPage
<
Weather
>
weatherPage
=
mapper
.
selectPage
(
page
,
null
);
// Page<Weather> weatherPage = mapper.selectPage(page, null);
System
.
out
.
println
(
"total : "
+
weatherPage
.
getTotal
());
System
.
out
.
println
(
"pages : "
+
weatherPage
.
getPages
());
for
(
Weather
weather
:
weatherPage
.
getRecords
())
{
IPage
<
Weather
>
weatherIPage
=
mapper
.
selectPage
(
page
,
null
);
System
.
out
.
println
(
"total : "
+
weatherIPage
.
getTotal
());
System
.
out
.
println
(
"pages : "
+
weatherIPage
.
getPages
());
for
(
Weather
weather
:
weatherIPage
.
getRecords
())
{
System
.
out
.
println
(
weather
);
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录