From 3ae555de4117907e24fb648fc1e16d76024e820c Mon Sep 17 00:00:00 2001 From: zyyang Date: Sat, 14 Nov 2020 14:00:37 +0800 Subject: [PATCH] change --- tests/examples/JDBC/mybatisplus-demo/pom.xml | 6 ++--- .../config/MybatisPlusConfig.java | 23 ++++++++++++++++ .../src/main/resources/application-prod.yml | 15 +++++------ .../src/main/resources/application.yml | 2 +- .../mapper/WeatherMapperTest.java | 27 +++++++++---------- 5 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java diff --git a/tests/examples/JDBC/mybatisplus-demo/pom.xml b/tests/examples/JDBC/mybatisplus-demo/pom.xml index e1bbcd9532..fc1d229330 100644 --- a/tests/examples/JDBC/mybatisplus-demo/pom.xml +++ b/tests/examples/JDBC/mybatisplus-demo/pom.xml @@ -103,12 +103,12 @@ prod - - true - prod + + true + diff --git a/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java b/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java new file mode 100644 index 0000000000..3ec9819c9b --- /dev/null +++ b/tests/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java @@ -0,0 +1,23 @@ +package com.taosdata.example.mybatisplusdemo.config; + +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MybatisPlusConfig { + + @Bean + public PaginationInterceptor paginationInnerInterceptor() { + PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); + // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false + // paginationInterceptor.setOverflow(false); + // 设置最大单页限制数量,默认 500 条,-1 不受限制 + // paginationInterceptor.setLimit(500); + // 开启 count 的 join 优化,只针对部分 left join +// paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true)); + return paginationInterceptor; + + } + +} diff --git a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml index 50e273103c..af688b76f4 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml +++ b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application-prod.yml @@ -1,13 +1,12 @@ spring: datasource: -# 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 - + # 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 driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://master:3306/test?useSSL=false username: root diff --git a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application.yml b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application.yml index f724f80979..fdd1c39eca 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application.yml +++ b/tests/examples/JDBC/mybatisplus-demo/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: @spring.profiles.active@ \ No newline at end of file + active: "@spring.profiles.active@" \ No newline at end of file diff --git a/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java b/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java index ab090d2efb..b7787d5477 100644 --- a/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java +++ b/tests/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java @@ -1,6 +1,7 @@ package com.taosdata.example.mybatisplusdemo.mapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.taosdata.example.mybatisplusdemo.domain.Weather; import org.junit.Assert; import org.junit.Test; @@ -37,24 +38,11 @@ public class WeatherMapperTest { weather.setTs(new Timestamp(1605024000000l)); weather.setTemperature(random.nextFloat() * 50); weather.setHumidity(random.nextInt(100)); - weather.setLocation("wangjing"); + weather.setLocation("望京"); int affectRows = mapper.insert(weather); Assert.assertEquals(1, affectRows); } - @Test - public void testDelete() { - mapper.delete(new QueryWrapper().eq("location", "wangjing")); - } - - @Test - public void testDeleteByMap() { - Map map = new HashMap<>(); - map.put("location", "wangjing"); - int affectRows = mapper.deleteByMap(map); -// Assert.assertEquals(0, affectRows); - } - @Test public void testSelectOne() { QueryWrapper wrapper = new QueryWrapper<>(); @@ -87,5 +75,16 @@ public class WeatherMapperTest { Assert.assertEquals(5, count); } + @Test + public void testSelectPage() { + Page page = new Page<>(1, 2); + Page weatherPage = mapper.selectPage(page, null); + System.out.println("total : " + weatherPage.getTotal()); + System.out.println("pages : " + weatherPage.getPages()); + for (Weather weather : weatherPage.getRecords()) { + System.out.println(weather); + } + } + } \ No newline at end of file -- GitLab