From a903058db4c13d062229c0cb2233642e8b7abf04 Mon Sep 17 00:00:00 2001 From: xiaoyekanren <876670773@qq.com> Date: Wed, 4 Jun 2025 14:29:27 +0800 Subject: [PATCH 1/7] add a example for mybatis, format markdown --- .../{readme.md => README.md} | 10 +- examples/mybatis-generator/pom.xml | 37 ++++++ .../java/org/apache/iotdb/mybatis/Main.java | 109 ++++++++++++++++++ .../src/main/resources/generatorConfig.xml | 4 +- .../src/main/resources/mybatis-config.xml | 18 +++ mybatis-generator/README-zh.md | 44 +++---- mybatis-generator/README.md | 44 +++---- 7 files changed, 216 insertions(+), 50 deletions(-) rename examples/mybatis-generator/{readme.md => README.md} (93%) create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java create mode 100644 examples/mybatis-generator/src/main/resources/mybatis-config.xml diff --git a/examples/mybatis-generator/readme.md b/examples/mybatis-generator/README.md similarity index 93% rename from examples/mybatis-generator/readme.md rename to examples/mybatis-generator/README.md index 7cbdab8a..6304bf69 100644 --- a/examples/mybatis-generator/readme.md +++ b/examples/mybatis-generator/README.md @@ -56,12 +56,12 @@ CREATE TABLE mix3 ( humidity FLOAT FIELD, status Boolean FIELD, arrival_time TIMESTAMP FIELD -) WITH (TTL=31536000000); +); ``` ### 3. Build Dependencies with Maven in your Project -``` +```xml @@ -89,9 +89,11 @@ CREATE TABLE mix3 ( The location of the ` configurationFile ` configuration ` generatorConfig.xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location -### 6. exec 'mvn mybatis-generator:generate' +### 6. generate generates corresponding Java classes and mapper files + +exec `mvn mybatis-generator:generate` -Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files +Execute the command at the location of the 'pom' in the project: Mvn mybatis generator: generate generates corresponding Java classes and mapper files ### 7、the target file location diff --git a/examples/mybatis-generator/pom.xml b/examples/mybatis-generator/pom.xml index c7d73e3f..f2d6360f 100644 --- a/examples/mybatis-generator/pom.xml +++ b/examples/mybatis-generator/pom.xml @@ -30,7 +30,44 @@ mybatis-generator-example IoTDB: Example: Mybatis Generator 2.0.2-SNAPHOT + + + org.mybatis + mybatis + 3.5.19 + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.8 + + + org.projectlombok + lombok + 1.18.38 + provided + + + org.apache.iotdb + iotdb-jdbc + 2.0.4-SNAPSHOT + + + + + src/main/resources + + **/*.xml + + + + src/main/java + + **/plugin/xml/*.xml + + + org.mybatis.generator diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java new file mode 100644 index 00000000..c1dc3beb --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java @@ -0,0 +1,109 @@ +package org.apache.iotdb.mybatis; + +import org.apache.iotdb.mybatis.plugin.mapper.MixMapper; +import org.apache.iotdb.mybatis.plugin.model.Mix; + +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException { + String resource = "mybatis-config.xml"; + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); + + try (SqlSession session = sqlSessionFactory.openSession(true)) { + MixMapper mapper = session.getMapper(MixMapper.class); + + Date now = new Date(); + + // 1. insertOne + System.out.println("1. insertOne..."); + insertOne(mapper, new Date(1)); + insertOne(mapper, new Date(2)); + insertOne(mapper, new Date(3)); + System.out.println("------------------\n"); + + // 2. selectAll + System.out.println("2. selectAll..."); + selectAll(mapper); + System.out.println("------------------\n"); + + // 3. selectByPrimaryKey + System.out.println("3. selectByPrimaryKey..."); + selectByPrimaryKey(mapper, new Date(1), "dev001"); + System.out.println("------------------\n"); + + // 4. deleteByPrimaryKey + System.out.println("4. deleteByPrimaryKey..."); + deleteByPrimaryKey(mapper, new Date(1), "dev001"); + deleteByPrimaryKey(mapper, new Date(2), "dev001"); + System.out.println("selectAll..."); + selectAll(mapper); + System.out.println("------------------\n"); + + // 5. batchInsert + System.out.println("5. batchInsert..."); + batchInsert(mapper, new Date(6)); + System.out.println("selectAll..."); + selectAll(mapper); + System.out.println("------------------\n"); + } + } + + private static void insertOne(MixMapper mapper, Date now) { + Mix mix = new Mix(); + mix.setTime(now); + mix.setDeviceId("dev001"); + mix.setRegion("华东"); + mix.setPlantId("plantA"); + mix.setModelId("modelX"); + mix.setMaintenance("正常"); + mix.setTemperature(25.5); + mix.setHumidity(60.0); + mix.setStatus(true); + mix.setArrivalTime(now); + mapper.insert(mix); + } + + private static void selectAll(MixMapper mapper) { + List all = mapper.selectAll(); + all.forEach(System.out::println); + } + + private static void selectByPrimaryKey(MixMapper mapper, Date time, String deviceId) { + Mix one = mapper.selectByPrimaryKey(time, deviceId); + System.out.println("results: " + one); + } + + private static void deleteByPrimaryKey(MixMapper mapper, Date time, String deviceId) { + mapper.deleteByPrimaryKey(time, deviceId); + } + + private static void batchInsert(MixMapper mapper, Date now) { + List batchList = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + Mix m = new Mix(); + m.setTime(new Date(now.getTime() + i * 1000)); + m.setDeviceId("dev00" + (i + 2)); + m.setRegion("华东"); + m.setPlantId("plantA"); + m.setModelId("modelX"); + m.setMaintenance("正常"); + m.setTemperature(20.0 + i); + m.setHumidity(50.0 + i); + m.setStatus(i % 2 == 0); + m.setArrivalTime(new Date(now.getTime() + i * 1000)); + batchList.add(m); + } + mapper.batchInsert(batchList); + } +} diff --git a/examples/mybatis-generator/src/main/resources/generatorConfig.xml b/examples/mybatis-generator/src/main/resources/generatorConfig.xml index 530ff4ff..6ad1c100 100644 --- a/examples/mybatis-generator/src/main/resources/generatorConfig.xml +++ b/examples/mybatis-generator/src/main/resources/generatorConfig.xml @@ -18,7 +18,7 @@ --> - + @@ -51,7 +51,7 @@ - +
diff --git a/examples/mybatis-generator/src/main/resources/mybatis-config.xml b/examples/mybatis-generator/src/main/resources/mybatis-config.xml new file mode 100644 index 00000000..e1e14767 --- /dev/null +++ b/examples/mybatis-generator/src/main/resources/mybatis-config.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/mybatis-generator/README-zh.md b/mybatis-generator/README-zh.md index 94eb875d..b8b2b3f4 100644 --- a/mybatis-generator/README-zh.md +++ b/mybatis-generator/README-zh.md @@ -24,28 +24,28 @@ * 在要生成的项目的 `pom` 文件中添加如下配置: -```java - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - - org.apache.iotdb - mybatis-generator-plugin - 2.0.2-SNAPSHOT - - - - true - true - src/main/resources/generatorConfig.xml - - - - +```xml + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + mybatis-generator-plugin + 2.0.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + ``` * `configurationFile` 配置 `generatorConfig.xml` 文件的位置,其内容在本项目的 `src/main/resources` 有一个模板供参考,`copy` 其内容放到相应的位置 diff --git a/mybatis-generator/README.md b/mybatis-generator/README.md index fbd3eb42..efc9df55 100644 --- a/mybatis-generator/README.md +++ b/mybatis-generator/README.md @@ -26,28 +26,28 @@ * Add the following configuration to the 'pom' file of the project to be generated: -```java - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - - org.apache.iotdb - mybatis-generator-plugin - 2.0.2-SNAPSHOT - - - - true - true - src/main/resources/generatorConfig.xml - - - - +```xml + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + mybatis-generator-plugin + 2.0.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + ``` * The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location From 8623a5c44b7b415dd5e194369a716fd35cfc488c Mon Sep 17 00:00:00 2001 From: Summer <43237967+2b3c511@users.noreply.github.com> Date: Wed, 4 Jun 2025 15:21:23 +0800 Subject: [PATCH 2/7] add default param (#77) * add default param * Update readme.md --------- Co-authored-by: 2b3c511 Co-authored-by: CritasWang --- examples/mybatis-generator/readme.md | 11 +++- .../src/main/resources/generatorConfig.xml | 2 +- .../resources/generatorConfigByExample.xml | 58 +++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 examples/mybatis-generator/src/main/resources/generatorConfigByExample.xml diff --git a/examples/mybatis-generator/readme.md b/examples/mybatis-generator/readme.md index 7cbdab8a..3d26403d 100644 --- a/examples/mybatis-generator/readme.md +++ b/examples/mybatis-generator/readme.md @@ -45,7 +45,7 @@ use test; ``` Then we need to create a database 'table' ``` -CREATE TABLE mix3 ( +CREATE TABLE mix ( time TIMESTAMP TIME, region STRING TAG, plant_id STRING TAG, @@ -87,7 +87,13 @@ CREATE TABLE mix3 ( ### 5. put The generatorConfig.xml in your project -The location of the ` configurationFile ` configuration ` generatorConfig.xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location +- `src/main/resources/generatorConfig.xml` + +each table generates an entity object + +- `src/main/resources/generatorConfigByExample.xml` + +The generated object will contain many "by Example" methods. If you do not want to generate these, you can configure to cancel them in the subsequent table elements ### 6. exec 'mvn mybatis-generator:generate' @@ -99,6 +105,7 @@ You can see the target file in your Project ``` org/apache/iotdb/mybatis/plugin/model/Mix.java +org/apache/iotdb/mybatis/plugin/model/MixExample.java org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml ``` diff --git a/examples/mybatis-generator/src/main/resources/generatorConfig.xml b/examples/mybatis-generator/src/main/resources/generatorConfig.xml index 530ff4ff..db1a991e 100644 --- a/examples/mybatis-generator/src/main/resources/generatorConfig.xml +++ b/examples/mybatis-generator/src/main/resources/generatorConfig.xml @@ -51,7 +51,7 @@ - +
diff --git a/examples/mybatis-generator/src/main/resources/generatorConfigByExample.xml b/examples/mybatis-generator/src/main/resources/generatorConfigByExample.xml new file mode 100644 index 00000000..63b45598 --- /dev/null +++ b/examples/mybatis-generator/src/main/resources/generatorConfigByExample.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
From 7f2069b6ea913d5a858c15dbd2739558d8a6a06f Mon Sep 17 00:00:00 2001 From: xiaoyekanren <876670773@qq.com> Date: Wed, 4 Jun 2025 16:26:39 +0800 Subject: [PATCH 3/7] add the code generated by mybatis --- examples/mybatis-generator/README.md | 2 +- .../mybatis/plugin/mapper/MixMapper.java | 25 +++++++++++ .../iotdb/mybatis/plugin/model/Mix.java | 45 +++++++++++++++++++ .../iotdb/mybatis/plugin/xml/MixMapper.xml | 23 ++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml diff --git a/examples/mybatis-generator/README.md b/examples/mybatis-generator/README.md index 6304bf69..e6aa65dd 100644 --- a/examples/mybatis-generator/README.md +++ b/examples/mybatis-generator/README.md @@ -45,7 +45,7 @@ use test; ``` Then we need to create a database 'table' ``` -CREATE TABLE mix3 ( +CREATE TABLE mix ( time TIMESTAMP TIME, region STRING TAG, plant_id STRING TAG, diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java new file mode 100644 index 00000000..6cc7bae3 --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java @@ -0,0 +1,25 @@ +/** + * Copyright From 2025, IoTDB. + * + *

MixMapper.java + */ +package org.apache.iotdb.mybatis.plugin.mapper; + +import org.apache.iotdb.mybatis.plugin.model.Mix; + +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +public interface MixMapper { + int deleteByPrimaryKey(@Param("time") Date time, @Param("deviceId") String deviceId); + + int insert(Mix row); + + Mix selectByPrimaryKey(@Param("time") Date time, @Param("deviceId") String deviceId); + + List selectAll(); + + int batchInsert(@Param("records") List records); +} diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java new file mode 100644 index 00000000..db185b09 --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java @@ -0,0 +1,45 @@ +/** + * Copyright From 2025, IoTDB. + * + *

Mix.java + */ +package org.apache.iotdb.mybatis.plugin.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * table: test.mix of model class + * + * @author IoTDB + * @date 2025-06-04 16:07:49 + */ +@Schema(title = "test.mix", description = "") +@Data +public class Mix implements Serializable { + /** class serial version id */ + private static final long serialVersionUID = 1L; + + private Date time; + + private String deviceId; + + private String region; + + private String plantId; + + private String modelId; + + private String maintenance; + + private Double temperature; + + private Double humidity; + + private Boolean status; + + private Date arrivalTime; +} diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml new file mode 100644 index 00000000..7bd815c7 --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + delete from test.mix where time = #{time,jdbcType=TIMESTAMP} and device_id = #{deviceId,jdbcType=VARCHAR} + insert into test.mix (time, device_id, region, plant_id, model_id, maintenance, temperature, humidity, status, arrival_time) values (#{time,jdbcType=TIMESTAMP}, #{deviceId,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR}, #{plantId,jdbcType=VARCHAR}, #{modelId,jdbcType=VARCHAR}, #{maintenance,jdbcType=VARCHAR}, #{temperature,jdbcType=FLOAT}, #{humidity,jdbcType=FLOAT}, #{status,jdbcType=BOOLEAN}, #{arrivalTime,jdbcType=TIMESTAMP}) + + + insert into test.mix ( time, device_id, region, plant_id, model_id, maintenance, temperature, humidity, status, arrival_time ) values + ( #{item.time,jdbcType=TIMESTAMP}, #{item.deviceId,jdbcType=VARCHAR}, #{item.region,jdbcType=VARCHAR}, #{item.plantId,jdbcType=VARCHAR}, #{item.modelId,jdbcType=VARCHAR}, #{item.maintenance,jdbcType=VARCHAR}, #{item.temperature,jdbcType=FLOAT}, #{item.humidity,jdbcType=FLOAT}, #{item.status,jdbcType=BOOLEAN}, #{item.arrivalTime,jdbcType=TIMESTAMP} ) + + From b583a77761e36066da99d34ab10d3f06f0e79710 Mon Sep 17 00:00:00 2001 From: xiaoyekanren <876670773@qq.com> Date: Wed, 4 Jun 2025 14:29:27 +0800 Subject: [PATCH 4/7] add a example for mybatis, format markdown --- .../{readme.md => README.md} | 10 +- examples/mybatis-generator/pom.xml | 37 ++++++ .../java/org/apache/iotdb/mybatis/Main.java | 109 ++++++++++++++++++ .../src/main/resources/generatorConfig.xml | 2 +- .../src/main/resources/mybatis-config.xml | 18 +++ mybatis-generator/README-zh.md | 44 +++---- mybatis-generator/README.md | 44 +++---- 7 files changed, 215 insertions(+), 49 deletions(-) rename examples/mybatis-generator/{readme.md => README.md} (93%) create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java create mode 100644 examples/mybatis-generator/src/main/resources/mybatis-config.xml diff --git a/examples/mybatis-generator/readme.md b/examples/mybatis-generator/README.md similarity index 93% rename from examples/mybatis-generator/readme.md rename to examples/mybatis-generator/README.md index 3d26403d..0b4ec58e 100644 --- a/examples/mybatis-generator/readme.md +++ b/examples/mybatis-generator/README.md @@ -56,12 +56,12 @@ CREATE TABLE mix ( humidity FLOAT FIELD, status Boolean FIELD, arrival_time TIMESTAMP FIELD -) WITH (TTL=31536000000); +); ``` ### 3. Build Dependencies with Maven in your Project -``` +```xml @@ -95,9 +95,11 @@ each table generates an entity object The generated object will contain many "by Example" methods. If you do not want to generate these, you can configure to cancel them in the subsequent table elements -### 6. exec 'mvn mybatis-generator:generate' +### 6. generate generates corresponding Java classes and mapper files + +exec `mvn mybatis-generator:generate` -Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files +Execute the command at the location of the 'pom' in the project: Mvn mybatis generator: generate generates corresponding Java classes and mapper files ### 7、the target file location diff --git a/examples/mybatis-generator/pom.xml b/examples/mybatis-generator/pom.xml index c7d73e3f..f2d6360f 100644 --- a/examples/mybatis-generator/pom.xml +++ b/examples/mybatis-generator/pom.xml @@ -30,7 +30,44 @@ mybatis-generator-example IoTDB: Example: Mybatis Generator 2.0.2-SNAPHOT + + + org.mybatis + mybatis + 3.5.19 + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.8 + + + org.projectlombok + lombok + 1.18.38 + provided + + + org.apache.iotdb + iotdb-jdbc + 2.0.4-SNAPSHOT + + + + + src/main/resources + + **/*.xml + + + + src/main/java + + **/plugin/xml/*.xml + + + org.mybatis.generator diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java new file mode 100644 index 00000000..c1dc3beb --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java @@ -0,0 +1,109 @@ +package org.apache.iotdb.mybatis; + +import org.apache.iotdb.mybatis.plugin.mapper.MixMapper; +import org.apache.iotdb.mybatis.plugin.model.Mix; + +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException { + String resource = "mybatis-config.xml"; + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); + + try (SqlSession session = sqlSessionFactory.openSession(true)) { + MixMapper mapper = session.getMapper(MixMapper.class); + + Date now = new Date(); + + // 1. insertOne + System.out.println("1. insertOne..."); + insertOne(mapper, new Date(1)); + insertOne(mapper, new Date(2)); + insertOne(mapper, new Date(3)); + System.out.println("------------------\n"); + + // 2. selectAll + System.out.println("2. selectAll..."); + selectAll(mapper); + System.out.println("------------------\n"); + + // 3. selectByPrimaryKey + System.out.println("3. selectByPrimaryKey..."); + selectByPrimaryKey(mapper, new Date(1), "dev001"); + System.out.println("------------------\n"); + + // 4. deleteByPrimaryKey + System.out.println("4. deleteByPrimaryKey..."); + deleteByPrimaryKey(mapper, new Date(1), "dev001"); + deleteByPrimaryKey(mapper, new Date(2), "dev001"); + System.out.println("selectAll..."); + selectAll(mapper); + System.out.println("------------------\n"); + + // 5. batchInsert + System.out.println("5. batchInsert..."); + batchInsert(mapper, new Date(6)); + System.out.println("selectAll..."); + selectAll(mapper); + System.out.println("------------------\n"); + } + } + + private static void insertOne(MixMapper mapper, Date now) { + Mix mix = new Mix(); + mix.setTime(now); + mix.setDeviceId("dev001"); + mix.setRegion("华东"); + mix.setPlantId("plantA"); + mix.setModelId("modelX"); + mix.setMaintenance("正常"); + mix.setTemperature(25.5); + mix.setHumidity(60.0); + mix.setStatus(true); + mix.setArrivalTime(now); + mapper.insert(mix); + } + + private static void selectAll(MixMapper mapper) { + List all = mapper.selectAll(); + all.forEach(System.out::println); + } + + private static void selectByPrimaryKey(MixMapper mapper, Date time, String deviceId) { + Mix one = mapper.selectByPrimaryKey(time, deviceId); + System.out.println("results: " + one); + } + + private static void deleteByPrimaryKey(MixMapper mapper, Date time, String deviceId) { + mapper.deleteByPrimaryKey(time, deviceId); + } + + private static void batchInsert(MixMapper mapper, Date now) { + List batchList = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + Mix m = new Mix(); + m.setTime(new Date(now.getTime() + i * 1000)); + m.setDeviceId("dev00" + (i + 2)); + m.setRegion("华东"); + m.setPlantId("plantA"); + m.setModelId("modelX"); + m.setMaintenance("正常"); + m.setTemperature(20.0 + i); + m.setHumidity(50.0 + i); + m.setStatus(i % 2 == 0); + m.setArrivalTime(new Date(now.getTime() + i * 1000)); + batchList.add(m); + } + mapper.batchInsert(batchList); + } +} diff --git a/examples/mybatis-generator/src/main/resources/generatorConfig.xml b/examples/mybatis-generator/src/main/resources/generatorConfig.xml index db1a991e..6ad1c100 100644 --- a/examples/mybatis-generator/src/main/resources/generatorConfig.xml +++ b/examples/mybatis-generator/src/main/resources/generatorConfig.xml @@ -18,7 +18,7 @@ --> - + diff --git a/examples/mybatis-generator/src/main/resources/mybatis-config.xml b/examples/mybatis-generator/src/main/resources/mybatis-config.xml new file mode 100644 index 00000000..e1e14767 --- /dev/null +++ b/examples/mybatis-generator/src/main/resources/mybatis-config.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/mybatis-generator/README-zh.md b/mybatis-generator/README-zh.md index 94eb875d..b8b2b3f4 100644 --- a/mybatis-generator/README-zh.md +++ b/mybatis-generator/README-zh.md @@ -24,28 +24,28 @@ * 在要生成的项目的 `pom` 文件中添加如下配置: -```java - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - - org.apache.iotdb - mybatis-generator-plugin - 2.0.2-SNAPSHOT - - - - true - true - src/main/resources/generatorConfig.xml - - - - +```xml + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + mybatis-generator-plugin + 2.0.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + ``` * `configurationFile` 配置 `generatorConfig.xml` 文件的位置,其内容在本项目的 `src/main/resources` 有一个模板供参考,`copy` 其内容放到相应的位置 diff --git a/mybatis-generator/README.md b/mybatis-generator/README.md index fbd3eb42..efc9df55 100644 --- a/mybatis-generator/README.md +++ b/mybatis-generator/README.md @@ -26,28 +26,28 @@ * Add the following configuration to the 'pom' file of the project to be generated: -```java - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - - org.apache.iotdb - mybatis-generator-plugin - 2.0.2-SNAPSHOT - - - - true - true - src/main/resources/generatorConfig.xml - - - - +```xml + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + mybatis-generator-plugin + 2.0.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + ``` * The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location From b9a15273fd87fc3fb6c08b1237a169ee45e6c77c Mon Sep 17 00:00:00 2001 From: xiaoyekanren <876670773@qq.com> Date: Wed, 4 Jun 2025 16:26:39 +0800 Subject: [PATCH 5/7] add the code generated by mybatis --- .../mybatis/plugin/mapper/MixMapper.java | 25 +++++++++++ .../iotdb/mybatis/plugin/model/Mix.java | 45 +++++++++++++++++++ .../iotdb/mybatis/plugin/xml/MixMapper.xml | 23 ++++++++++ 3 files changed, 93 insertions(+) create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java create mode 100644 examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java new file mode 100644 index 00000000..6cc7bae3 --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java @@ -0,0 +1,25 @@ +/** + * Copyright From 2025, IoTDB. + * + *

MixMapper.java + */ +package org.apache.iotdb.mybatis.plugin.mapper; + +import org.apache.iotdb.mybatis.plugin.model.Mix; + +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +public interface MixMapper { + int deleteByPrimaryKey(@Param("time") Date time, @Param("deviceId") String deviceId); + + int insert(Mix row); + + Mix selectByPrimaryKey(@Param("time") Date time, @Param("deviceId") String deviceId); + + List selectAll(); + + int batchInsert(@Param("records") List records); +} diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java new file mode 100644 index 00000000..db185b09 --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java @@ -0,0 +1,45 @@ +/** + * Copyright From 2025, IoTDB. + * + *

Mix.java + */ +package org.apache.iotdb.mybatis.plugin.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * table: test.mix of model class + * + * @author IoTDB + * @date 2025-06-04 16:07:49 + */ +@Schema(title = "test.mix", description = "") +@Data +public class Mix implements Serializable { + /** class serial version id */ + private static final long serialVersionUID = 1L; + + private Date time; + + private String deviceId; + + private String region; + + private String plantId; + + private String modelId; + + private String maintenance; + + private Double temperature; + + private Double humidity; + + private Boolean status; + + private Date arrivalTime; +} diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml new file mode 100644 index 00000000..7bd815c7 --- /dev/null +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + delete from test.mix where time = #{time,jdbcType=TIMESTAMP} and device_id = #{deviceId,jdbcType=VARCHAR} + insert into test.mix (time, device_id, region, plant_id, model_id, maintenance, temperature, humidity, status, arrival_time) values (#{time,jdbcType=TIMESTAMP}, #{deviceId,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR}, #{plantId,jdbcType=VARCHAR}, #{modelId,jdbcType=VARCHAR}, #{maintenance,jdbcType=VARCHAR}, #{temperature,jdbcType=FLOAT}, #{humidity,jdbcType=FLOAT}, #{status,jdbcType=BOOLEAN}, #{arrivalTime,jdbcType=TIMESTAMP}) + + + insert into test.mix ( time, device_id, region, plant_id, model_id, maintenance, temperature, humidity, status, arrival_time ) values + ( #{item.time,jdbcType=TIMESTAMP}, #{item.deviceId,jdbcType=VARCHAR}, #{item.region,jdbcType=VARCHAR}, #{item.plantId,jdbcType=VARCHAR}, #{item.modelId,jdbcType=VARCHAR}, #{item.maintenance,jdbcType=VARCHAR}, #{item.temperature,jdbcType=FLOAT}, #{item.humidity,jdbcType=FLOAT}, #{item.status,jdbcType=BOOLEAN}, #{item.arrivalTime,jdbcType=TIMESTAMP} ) + + From 140d2ab3b32cc53dc74683df0d4e7e0fd2b9a178 Mon Sep 17 00:00:00 2001 From: CritasWang Date: Wed, 4 Jun 2025 17:55:28 +0800 Subject: [PATCH 6/7] fix compile --- examples/mybatis-generator/pom.xml | 20 ++++++++++++++----- .../java/org/apache/iotdb/mybatis/Main.java | 19 ++++++++++++++++++ .../mybatis/plugin/mapper/MixMapper.java | 20 ++++++++++++++++--- .../iotdb/mybatis/plugin/model/Mix.java | 20 ++++++++++++++++--- .../iotdb/mybatis/plugin/xml/MixMapper.xml | 17 ++++++++++++++++ .../src/main/resources/mybatis-config.xml | 17 ++++++++++++++++ 6 files changed, 102 insertions(+), 11 deletions(-) diff --git a/examples/mybatis-generator/pom.xml b/examples/mybatis-generator/pom.xml index f2d6360f..39c714d6 100644 --- a/examples/mybatis-generator/pom.xml +++ b/examples/mybatis-generator/pom.xml @@ -36,11 +36,6 @@ mybatis 3.5.19 - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.8.8 - org.projectlombok lombok @@ -52,6 +47,11 @@ iotdb-jdbc 2.0.4-SNAPSHOT + + io.swagger.core.v3 + swagger-annotations-jakarta + 2.2.30 + @@ -86,6 +86,16 @@ src/main/resources/generatorConfig.xml + + org.apache.maven.plugins + maven-dependency-plugin + + + + org.apache.iotdb:iotdb-jdbc + + + diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java index c1dc3beb..5fb32d64 100644 --- a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/Main.java @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.iotdb.mybatis; import org.apache.iotdb.mybatis.plugin.mapper.MixMapper; diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java index 6cc7bae3..fb54c92d 100644 --- a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java @@ -1,8 +1,22 @@ -/** - * Copyright From 2025, IoTDB. +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - *

MixMapper.java + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ + package org.apache.iotdb.mybatis.plugin.mapper; import org.apache.iotdb.mybatis.plugin.model.Mix; diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java index db185b09..d32e3e45 100644 --- a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/model/Mix.java @@ -1,8 +1,22 @@ -/** - * Copyright From 2025, IoTDB. +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 * - *

Mix.java + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ + package org.apache.iotdb.mybatis.plugin.model; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml index 7bd815c7..ea23c977 100644 --- a/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml +++ b/examples/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml @@ -1,5 +1,22 @@ + diff --git a/examples/mybatis-generator/src/main/resources/mybatis-config.xml b/examples/mybatis-generator/src/main/resources/mybatis-config.xml index e1e14767..06dfbe99 100644 --- a/examples/mybatis-generator/src/main/resources/mybatis-config.xml +++ b/examples/mybatis-generator/src/main/resources/mybatis-config.xml @@ -1,5 +1,22 @@ + From fa7c565d7d34c8644f3ac3bd50b8706795b0d55d Mon Sep 17 00:00:00 2001 From: CritasWang Date: Wed, 4 Jun 2025 18:15:52 +0800 Subject: [PATCH 7/7] Update README.md --- examples/mybatis-generator/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/mybatis-generator/README.md b/examples/mybatis-generator/README.md index 0b4ec58e..234f0a6b 100644 --- a/examples/mybatis-generator/README.md +++ b/examples/mybatis-generator/README.md @@ -105,6 +105,13 @@ Execute the command at the location of the 'pom' in the project: Mvn mybatis gen You can see the target file in your Project +``` +org/apache/iotdb/mybatis/plugin/model/Mix.java +org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java +org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml +``` + +if you are using the 'src/main/resources/generatorConfiguraByExample. xml' file`, You can see the target file in your Project ``` org/apache/iotdb/mybatis/plugin/model/Mix.java org/apache/iotdb/mybatis/plugin/model/MixExample.java