```xml
<dependency>
    <groupId>org.dromara.autotable</groupId>
    <artifactId>auto-table-solon-plugin</artifactId>
    <version>2.2.1</version>
</dependency>
```


> 最新版本查看
[https://central.sonatype.com/artifact/org.dromara.autotable/auto-table-solon-plugin](https://central.sonatype.com/artifact/org.dromara.autotable/auto-table-solon-plugin)


### 1、描述

AutoTable插件，根据 Java 实体，自动映射成数据库的表结构。。

用过 `JPA` 的都知道，`JPA` 有一项重要的能力就是表结构自动维护，这让我们可以专注于业务逻辑和实体，而不需要关心数据库的表、列的配置，尤其是对于开发阶段需要频繁的新增表及变更表结构，节省了大量手动工作。

但是在 `Mybatis` 圈子中，一直缺少这种体验，所以 `AutoTable` 应运而生了。

### 2、数据库支持

> 以下的测试版本是我本地的版本或者部分小伙伴测试过的版本，更低的版本未做详细测试，但不代表不能用，所以有测试过其他更低版本的小伙伴欢迎联系我修改相关版本号，感谢🫡

| 数据库          | 测试版本       | 说明                         |
|--------------|------------|----------------------------|
| ✅ MySQL      | 5.7        |                            |
| ✅ MariaDB    | 对应MySQL的版本 | 协议使用MySQL，即`jdbc:mysql://` |
| ✅ PostgreSQL | 15.5       |                            |
| ✅ SQLite     | 3.35.5     |                            |
| ✅ H2         | 2.2.220    |                            |
| 其他数据库        | 暂未支持       | 期待你的PR😉                   |

### 3、快速上手

#### 第 1 步：添加Maven依赖


```xml [Solon应用]
<dependency>
    <groupId>org.dromara.autotable</groupId>
    <artifactId>auto-table-solon-plugin</artifactId>
    <version>[maven仓库最新版本]</version>
</dependency>
```


#### 第 2 步：激活实体

```java
@Data
@AutoTable // 声明表信息（默认表名使用类名转下划线，即'test_table'） // [!code ++]
public class TestTable {

    private Integer id;

    private String username;

    private Integer age;

    private String phone;
}

```

#### 第 3 步：激活AutoTable


```java [Solon应用]
@EnableAutoTable // 声明使用AutoTable框架 // [!code ++]
@SolonMain
public class DemoAutoTableApplication {
    public static void main(String[] args) {
        Solon.start(Application.class, args);
    }
}
```


#### 第 4 步： 配置数据源


```yml
#数据源配置块（名字按业务需要取，与 @Db 那边对起来就好）
solon.dataSources:
  db1!:
    class: "com.zaxxer.hikari.HikariDataSource"
    jdbcUrl: jdbc:mysql://localhost:3306/rock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true
    driverClassName: com.mysql.cj.jdbc.Driver
    username: root
    password: 123456
```

#### 第 5 步：重启项目

查看控制台信息与数据库表和字段是否生成


### 具体参考官方文档：

[https://autotable.tangzc.com/](https://autotable.tangzc.com/)
