# db_creator **Repository Path**: own_2022/db_creator ## Basic Information - **Project Name**: db_creator - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-15 - **Last Updated**: 2026-06-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DB Creator 一个基于 Spring Boot 的数据库表自动创建框架。 ## 简介 DB Creator 是一个简化数据库表创建的框架,通过注解驱动的方式,自动根据实体类生成数据库表结构。只需在实体类上添加相应的注解,即可实现表的自动创建、维护以及索引管理。 ## 功能特性 - **注解驱动**:通过 `@AutoTable` 注解自动创建表 - **自动主键**:支持自增主键定义 - **字段配置**:支持字段注释、类型、长度、非空约束等配置 - **索引管理**:通过 `@Index` 注解轻松创建索引 - **默认值**:支持设置字段默认值 ## 快速开始 ### 1. 添加依赖 在 `pom.xml` 中添加项目依赖: ```xml com.wwlwxg dbcreate 1.0.0 ``` ### 2. 启用自动表功能 在 Spring Boot 启动类上添加 `@EnableAutoTable` 注解: ```java @EnableAutoTable @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` ### 3. 创建实体类 使用 `@AutoTable` 注解标记实体类,并配置字段: ```java @Data @AutoTable(comment = "用户表") public class User { @PrimaryKey(autoIncrement = true) private Long id; @ColumnComment("用户名") @ColumnNotNull @ColumnType(length = 50) private String username; @ColumnComment("邮箱") @Index private String email; @ColumnComment("年龄") private Integer age; @ColumnComment("创建时间") @ColumnDefault("CURRENT_TIMESTAMP") private LocalDateTime createTime; } ``` ## 注解说明 | 注解 | 说明 | |------|------| | `@EnableAutoTable` | 启用自动表创建功能,放在启动类上 | | `@AutoTable` | 标记实体类为自动创建的表,`comment` 属性用于设置表注释 | | `@PrimaryKey` | 标记主键字段,`autoIncrement` 设置是否自增 | | `@ColumnComment` | 设置字段注释 | | `@ColumnNotNull` | 设置字段非空约束 | | `@ColumnType` | 设置字段类型,`length` 设置长度 | | `@Index` | 在字段上添加此注解创建索引 | | `@ColumnDefault` | 设置字段默认值 | ## 配置示例 在 `application.yml` 中配置数据源: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/testdb username: root password: your_password driver-class-name: com.mysql.cj.jdbc.Driver ``` ## 许可证 本项目基于 MIT 许可证开源。