diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Column.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Column.java index 6371b82a..bfaf44e6 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Column.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Column.java @@ -86,4 +86,9 @@ public @interface Column { */ Class typeHandler() default UnknownTypeHandler.class; -} \ No newline at end of file + /** + * 数据字段注释,在 AI 时代,注释的内容往往可用于 AI 辅助对话 + */ + String comment() default ""; + +} diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Id.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Id.java index d960aed8..a62d2a30 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Id.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Id.java @@ -50,4 +50,9 @@ public @interface Id { */ boolean before() default true; -} \ No newline at end of file + + /** + * 数据库字段注释,在 AI 时代,注释的内容往往可用于 AI 辅助对话 + */ + String comment() default ""; +} diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Table.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Table.java index 9abc8761..c4e17786 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Table.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/Table.java @@ -47,6 +47,11 @@ public @interface Table { */ String dataSource() default ""; + /** + * 数据库表注释,在 AI 时代,注释的内容往往可用于 AI 辅助对话 + */ + String comment() default ""; + /** * 监听 entity 的 insert 行为。 */ diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java index e9a95d5d..581e79c0 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java @@ -53,6 +53,11 @@ public class ColumnInfo { */ protected String property; + /** + * 数据库字段注释,在 AI 时代,注释的内容往往可用于 AI 辅助对话 + */ + protected String comment; + /** * 属性类型。 */ @@ -108,6 +113,14 @@ public class ColumnInfo { this.property = property; } + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + public Class getPropertyType() { return propertyType; } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java index 3ad66d08..7d0f76b7 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java @@ -49,6 +49,7 @@ public class IdInfo extends ColumnInfo { this.keyType = id.keyType(); this.value = id.value(); this.before = id.before(); + this.comment = id.comment(); initDefaultKeyType(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index c86e742d..a9e421d3 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -99,6 +99,8 @@ public class TableInfo { private String schema; // schema private boolean camelToUnderline = true; private String dataSource; + + private String comment; private String tableName; // 表名 private Class entityClass; // 实体类 // 逻辑删除数据库列名 @@ -216,6 +218,14 @@ public class TableInfo { this.dataSource = dataSource; } + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + public String getLogicDeleteColumnOrSkip() { return LogicDeleteManager.getLogicDeleteColumn(logicDeleteColumn); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java index 4e27a315..ad752e20 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java @@ -226,6 +226,7 @@ public class TableInfoFactory { tableInfo.setSchema(table.schema()); tableInfo.setTableName(table.value()); tableInfo.setCamelToUnderline(table.camelToUnderline()); + tableInfo.setComment(tableInfo.getComment()); if (table.onInsert().length > 0) { List insertListeners = Arrays.stream(table.onInsert()) @@ -424,6 +425,10 @@ public class TableInfoFactory { columnInfo.setPropertyType(fieldType); columnInfo.setIgnore(columnAnnotation != null && columnAnnotation.ignore()); + if (columnAnnotation != null) { + columnInfo.setComment(columnAnnotation.comment()); + } + // 默认查询列 没有忽略且不是大字段 if (columnAnnotation == null || (!columnAnnotation.isLarge() && !columnAnnotation.ignore())) {