Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions examples/mybatisplus-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<!--

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.

-->
# MybatisPlus-Generator Demo
## Introduction

This demo shows how to use IoTDB-MybatisPlus-Generator

### Version usage

IoTDB: 2.0.1-beta
mybatisPlus: 3.5.10

### 1. Install IoTDB

please refer to [https://iotdb.apache.org/#/Download](https://iotdb.apache.org/#/Download)

### 2. Startup IoTDB

please refer to [Quick Start](http://iotdb.apache.org/UserGuide/Master/Get%20Started/QuickStart.html)

Then we need to create a database 'test' by cli in table model
```
create database test;
use test;
```
Then we need to create a database 'table'
```sql
CREATE TABLE mix (
time TIMESTAMP TIME,
region STRING TAG,
plant_id STRING TAG,
device_id STRING TAG,
model_id STRING ATTRIBUTE,
maintenance STRING ATTRIBUTE,
temperature FLOAT FIELD,
humidity FLOAT FIELD,
status Boolean FIELD,
arrival_time TIMESTAMP FIELD
) WITH (TTL=31536000000);
```

### 3. Build Dependencies with Maven in your Project

```
<properties>
<mybatisplus.version>3.5.10</mybatisplus.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>3.4.5</spring-boot.version>
<spring.version>6.2.6</spring.version>
<iotdb-jdbc.version>2.0.4-SNAPSHOT</iotdb-jdbc.version>
<io-springfox.version>3.0.0</io-springfox.version>
</properties>

<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>${mybatisplus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>${mybatisplus.version}</version>
</dependency>

<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
<version>${iotdb-jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io-springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${io-springfox.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</dependency>
<dependency>
<groupId>com.github.jeffreyning</groupId>
<artifactId>mybatisplus-plus</artifactId>
<version>1.7.5-RELEASE</version>
</dependency>
</dependencies>
```

### 4. Start the Main.java

### 5. the target file location

You can see the target file in your Project
```
org/apache/iotdb/controller/MixController.java
org/apache/iotdb/entity/Mix.java
org/apache/iotdb/mapper/MixMapper.xml
org/apache/iotdb/service/MixService.java
org/apache/iotdb/service/MixServiceImpl.java
org/apache/iotdb/MixMapper.xml

```

### 6. add & alter Annotations

The generated code files `entity/Table1.java` and `entity/Table2.java` need to be manually adjusted to support multi-primary key queries.

```java
// add import
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;

// add @MppMultiId
@MppMultiId
// alter @TableId() -->> @TableField()
@TableField("time")
private Date time;

// add @MppMultiId
@MppMultiId
// alter @TableId() -->> @TableField()
@TableField("region")
private String region;

// add @MppMultiId
@MppMultiId
// alter @TableId() -->> @TableField()
@TableField("plant_id")
private String plantId;

// add @MppMultiId
@MppMultiId
// alter @TableId() -->> @TableField()
@TableField("device_id")
private String deviceId;
//

```

82 changes: 45 additions & 37 deletions examples/mybatisplus-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,31 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-extras-parent</artifactId>
<version>2.0.4-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>org.apache.iotdb</groupId>
<artifactId>mybatisplus-generator-example</artifactId>
<name>IoTDB: Example: Mybatis Plus Generator</name>
<version>2.0.4-SNAPHOT</version>

<properties>
<mybatisplus.version>3.5.10</mybatisplus.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>3.4.5</spring-boot.version>
<spring.version>6.2.6</spring.version>
<iotdb-jdbc.version>2.0.4-SNAPSHOT</iotdb-jdbc.version>
<io-springfox.version>3.0.0</io-springfox.version>
</properties>

<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.19</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
Expand All @@ -53,17 +54,13 @@
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.10</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.4.1</version>
<version>${mybatisplus.version}</version>
</dependency>

<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
<version>${iotdb.version}</version>
<version>${iotdb-jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -76,44 +73,55 @@
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.6</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io-springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${io-springfox.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</dependency>
<dependency>
<groupId>com.github.jeffreyning</groupId>
<artifactId>mybatisplus-plus</artifactId>
<version>1.7.5-RELEASE</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<ignoredDependencies>
<!-- For some reason this plugin missed it being used for a constant import -->
<ignoredDependency>org.apache.iotdb:isession</ignoredDependency>
</ignoredDependencies>
<usedDependencies>
<!-- These are used at runtime in tests -->
<usedDependency>com.baomidou:mybatis-plus-spring-boot3-starter</usedDependency>
<usedDependency>org.apache.velocity:velocity-engine-core</usedDependency>
<usedDependency>org.springframework.boot:spring-boot-starter</usedDependency>
<usedDependency>org.springframework.boot:spring-boot-starter-web</usedDependency>
<usedDependency>org.springdoc:springdoc-openapi-starter-webmvc-ui</usedDependency>
<usedDependency>org.projectlombok:lombok</usedDependency>
</usedDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.4.2</version>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>2.0.2-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<skip>true</skip>
<verbose>true</verbose>
<overwrite>true</overwrite>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>

</project>
Loading