|
| 1 | +<!-- |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + or more contributor license agreements. See the NOTICE file |
| 5 | + distributed with this work for additional information |
| 6 | + regarding copyright ownership. The ASF licenses this file |
| 7 | + to you under the Apache License, Version 2.0 (the |
| 8 | + "License"); you may not use this file except in compliance |
| 9 | + with the License. You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | + Unless required by applicable law or agreed to in writing, |
| 14 | + software distributed under the License is distributed on an |
| 15 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + KIND, either express or implied. See the License for the |
| 17 | + specific language governing permissions and limitations |
| 18 | + under the License. |
| 19 | +
|
| 20 | +--> |
| 21 | +# MybatisPlus-Generator Demo |
| 22 | +## Introduction |
| 23 | + |
| 24 | +This demo shows how to use IoTDB-MybatisPlus-Generator |
| 25 | + |
| 26 | +### Version usage |
| 27 | + |
| 28 | +IoTDB: 2.0.1-beta |
| 29 | +mybatisPlus: 3.5.10 |
| 30 | + |
| 31 | +### 1. Install IoTDB |
| 32 | + |
| 33 | +please refer to [https://iotdb.apache.org/#/Download](https://iotdb.apache.org/#/Download) |
| 34 | + |
| 35 | +### 2. Startup IoTDB |
| 36 | + |
| 37 | +please refer to [Quick Start](http://iotdb.apache.org/UserGuide/Master/Get%20Started/QuickStart.html) |
| 38 | + |
| 39 | +Then we need to create a database 'test' by cli in table model |
| 40 | +``` |
| 41 | +create database test; |
| 42 | +use test; |
| 43 | +``` |
| 44 | +Then we need to create a database 'table' |
| 45 | +```sql |
| 46 | +CREATE TABLE mix ( |
| 47 | + time TIMESTAMP TIME, |
| 48 | + region STRING TAG, |
| 49 | + plant_id STRING TAG, |
| 50 | + device_id STRING TAG, |
| 51 | + model_id STRING ATTRIBUTE, |
| 52 | + maintenance STRING ATTRIBUTE, |
| 53 | + temperature FLOAT FIELD, |
| 54 | + humidity FLOAT FIELD, |
| 55 | + status Boolean FIELD, |
| 56 | + arrival_time TIMESTAMP FIELD |
| 57 | +) WITH (TTL=31536000000); |
| 58 | +``` |
| 59 | + |
| 60 | +### 3. Build Dependencies with Maven in your Project |
| 61 | + |
| 62 | +``` |
| 63 | +<properties> |
| 64 | + <mybatisplus.version>3.5.10</mybatisplus.version> |
| 65 | + <maven.compiler.source>17</maven.compiler.source> |
| 66 | + <maven.compiler.target>17</maven.compiler.target> |
| 67 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 68 | + <spring-boot.version>3.4.5</spring-boot.version> |
| 69 | + <spring.version>6.2.6</spring.version> |
| 70 | + <iotdb-jdbc.version>2.0.4-SNAPSHOT</iotdb-jdbc.version> |
| 71 | + <io-springfox.version>3.0.0</io-springfox.version> |
| 72 | +</properties> |
| 73 | +
|
| 74 | +<dependencies> |
| 75 | + <dependency> |
| 76 | + <groupId>com.baomidou</groupId> |
| 77 | + <artifactId>mybatis-plus-spring-boot3-starter</artifactId> |
| 78 | + <version>${mybatisplus.version}</version> |
| 79 | + </dependency> |
| 80 | + <dependency> |
| 81 | + <groupId>com.baomidou</groupId> |
| 82 | + <artifactId>mybatis-plus-generator</artifactId> |
| 83 | + <version>${mybatisplus.version}</version> |
| 84 | + </dependency> |
| 85 | +
|
| 86 | + <dependency> |
| 87 | + <groupId>org.apache.iotdb</groupId> |
| 88 | + <artifactId>iotdb-jdbc</artifactId> |
| 89 | + <version>${iotdb-jdbc.version}</version> |
| 90 | + </dependency> |
| 91 | + <dependency> |
| 92 | + <groupId>org.springframework.boot</groupId> |
| 93 | + <artifactId>spring-boot-starter</artifactId> |
| 94 | + <version>${spring-boot.version}</version> |
| 95 | + </dependency> |
| 96 | + <dependency> |
| 97 | + <groupId>org.springframework.boot</groupId> |
| 98 | + <artifactId>spring-boot-starter-web</artifactId> |
| 99 | + <version>${spring-boot.version}</version> |
| 100 | + </dependency> |
| 101 | + <dependency> |
| 102 | + <groupId>org.springframework.boot</groupId> |
| 103 | + <artifactId>spring-boot-starter-test</artifactId> |
| 104 | + <version>${spring-boot.version}</version> |
| 105 | + <scope>test</scope> |
| 106 | + </dependency> |
| 107 | +
|
| 108 | + <dependency> |
| 109 | + <groupId>io.springfox</groupId> |
| 110 | + <artifactId>springfox-swagger2</artifactId> |
| 111 | + <version>${io-springfox.version}</version> |
| 112 | + </dependency> |
| 113 | + <dependency> |
| 114 | + <groupId>io.springfox</groupId> |
| 115 | + <artifactId>springfox-swagger-ui</artifactId> |
| 116 | + <version>${io-springfox.version}</version> |
| 117 | + </dependency> |
| 118 | +
|
| 119 | + <dependency> |
| 120 | + <groupId>org.projectlombok</groupId> |
| 121 | + <artifactId>lombok</artifactId> |
| 122 | + <version>1.18.36</version> |
| 123 | + </dependency> |
| 124 | + <dependency> |
| 125 | + <groupId>com.github.jeffreyning</groupId> |
| 126 | + <artifactId>mybatisplus-plus</artifactId> |
| 127 | + <version>1.7.5-RELEASE</version> |
| 128 | + </dependency> |
| 129 | +</dependencies> |
| 130 | +``` |
| 131 | + |
| 132 | +### 4. Start the Main.java |
| 133 | + |
| 134 | +### 5. the target file location |
| 135 | + |
| 136 | +You can see the target file in your Project |
| 137 | +``` |
| 138 | +org/apache/iotdb/controller/MixController.java |
| 139 | +org/apache/iotdb/entity/Mix.java |
| 140 | +org/apache/iotdb/mapper/MixMapper.xml |
| 141 | +org/apache/iotdb/service/MixService.java |
| 142 | +org/apache/iotdb/service/MixServiceImpl.java |
| 143 | +org/apache/iotdb/MixMapper.xml |
| 144 | +
|
| 145 | +``` |
| 146 | + |
| 147 | +### 6. add & alter Annotations |
| 148 | + |
| 149 | +The generated code files `entity/Table1.java` and `entity/Table2.java` need to be manually adjusted to support multi-primary key queries. |
| 150 | + |
| 151 | +```java |
| 152 | +// add import |
| 153 | +import com.github.jeffreyning.mybatisplus.anno.MppMultiId; |
| 154 | + |
| 155 | +// add @MppMultiId |
| 156 | +@MppMultiId |
| 157 | +// alter @TableId() -->> @TableField() |
| 158 | +@TableField("time") |
| 159 | +private Date time; |
| 160 | + |
| 161 | +// add @MppMultiId |
| 162 | +@MppMultiId |
| 163 | +// alter @TableId() -->> @TableField() |
| 164 | +@TableField("region") |
| 165 | +private String region; |
| 166 | + |
| 167 | +// add @MppMultiId |
| 168 | +@MppMultiId |
| 169 | +// alter @TableId() -->> @TableField() |
| 170 | +@TableField("plant_id") |
| 171 | +private String plantId; |
| 172 | + |
| 173 | +// add @MppMultiId |
| 174 | +@MppMultiId |
| 175 | +// alter @TableId() -->> @TableField() |
| 176 | +@TableField("device_id") |
| 177 | +private String deviceId; |
| 178 | +// |
| 179 | + |
| 180 | +``` |
| 181 | + |
0 commit comments