注解速查
本页列出 AutoTable 所有注解,便于快速查阅。
表级注解
| 注解 | 作用 | 必需 | 详情 |
|---|---|---|---|
@AutoTable | 激活表自动维护,指定表名/schema/注释 | ✅ | 查看 |
@Ignore | 忽略实体,不参与表维护 | 查看 | |
@MysqlEngine | MySQL 专属,指定表引擎 | 查看 | |
@MysqlCharset | MySQL 专属,指定表字符集 | 查看 |
@AutoTable 参数
java
@AutoTable(
value = "user", // 表名,默认类名转下划线
schema = "", // schema,默认从连接获取
comment = "用户表", // 表注释
dialect = "", // 指定数据库方言
initSql = "" // 初始化 SQL 文件路径
)列级注解
| 注解 | 作用 | 详情 |
|---|---|---|
@AutoColumn | 聚合注解,一次性配置列属性 | 查看 |
@AutoColumns | 多数据库适配,配置多个 @AutoColumn | 查看 |
@ColumnName | 指定列名 | 查看 |
@ColumnType | 指定列类型和长度 | 查看 |
@ColumnNotNull | 非空约束 | 查看 |
@ColumnDefault | 默认值 | 查看 |
@ColumnComment | 列注释 | 查看 |
@Ignore | 忽略字段 | 查看 |
@AutoColumn 参数
java
@AutoColumn(
value = "user_name", // 列名
type = "varchar", // 类型
length = 50, // 长度
decimalLength = 2, // 小数位
notNull = true, // 非空
defaultValue = "", // 默认值
defaultValueType = UNDEFINED, // 默认值类型
comment = "用户名", // 注释
sort = 0, // 排序
dialect = "" // 指定数据库
)@ColumnDefault 默认值类型
| 类型 | 说明 |
|---|---|
UNDEFINED | 使用 value 属性值 |
EMPTY_STRING | 空字符串 '' |
NULL | NULL 值 |
主键注解
| 注解 | 作用 | 详情 |
|---|---|---|
@PrimaryKey | 声明主键 | 查看 |
@AutoIncrement | 声明自增(非主键也可用) | 查看 |
@PrimaryKey 参数
java
@PrimaryKey(
autoIncrement = true // 是否自增
)索引注解
| 注解 | 作用 | 详情 |
|---|---|---|
@Index | 字段级索引 | 查看 |
@IndexField | 复合索引中的字段配置 | 查看 |
@TableIndex | 表级索引(复合索引) | 查看 |
@TableIndexes | 多个表级索引 | 查看 |
@Index 参数
java
@Index(
name = "idx_email", // 索引名,空则自动生成
type = IndexTypeEnum.NORMAL, // 索引类型
method = "", // 索引方法(BTREE/HASH 等)
comment = "" // 索引注释
)索引类型 IndexTypeEnum
| 类型 | 说明 |
|---|---|
NORMAL | 普通索引 |
UNIQUE | 唯一索引 |
FULLTEXT | 全文索引(MySQL) |
@TableIndex 参数
java
@TableIndex(
name = "idx_name_age", // 索引名
fields = {"name", "age"}, // 字段列表
type = IndexTypeEnum.NORMAL
)MySQL 专属注解
| 注解 | 作用 |
|---|---|
@MysqlEngine | 表引擎(InnoDB/MyISAM) |
@MysqlCharset | 表/列字符集和排序规则 |
@MysqlColumnCharset | 列字符集 |
@MysqlColumnUnsigned | 无符号数字 |
@MysqlColumnZerofill | 前置补零 |
拦截器接口
| 接口 | 触发时机 | 详情 |
|---|---|---|
AutoTableAnnotationInterceptor | 注解扫描前 | 查看 |
BuildTableMetadataInterceptor | 元数据构建后 | 查看 |
CreateTableInterceptor | 建表前 | 查看 |
ModifyTableInterceptor | 改表前 | 查看 |
回调接口
| 接口 | 触发时机 | 详情 |
|---|---|---|
AutoTableReadyCallback | 启动前 | 查看 |
CreateDatabaseFinishCallback | 数据库创建后 | 查看 |
CreateTableFinishCallback | 表创建后 | 查看 |
ModifyTableFinishCallback | 表修改后 | 查看 |
DeleteTableFinishCallback | 表删除后 | 查看 |
CompareTableFinishCallback | 表比对后 | 查看 |
ValidateFinishCallback | 校验完成后 | 查看 |
RunBeforeCallback | 单表执行前 | 查看 |
RunAfterCallback | 单表执行后 | 查看 |
AutoTableFinishCallback | 全部完成后 | 查看 |
快速示例
java
@Data
@AutoTable(comment = "用户表")
@MysqlCharset(charset = "utf8mb4", collate = "utf8mb4_general_ci")
@TableIndex(name = "idx_name_age", fields = {"username", "age"})
public class User {
@PrimaryKey(autoIncrement = true)
private Long id;
@AutoColumn(value = "user_name", length = 50, notNull = true, comment = "用户名")
private String username;
@ColumnComment("邮箱")
@Index(type = IndexTypeEnum.UNIQUE)
private String email;
@ColumnDefault("0")
private Integer age;
@ColumnType(value = "text")
private String bio;
@Ignore // 忽略此字段
private transient String tempData;
}