feat: add "comment" config for table annotations

This commit is contained in:
Michael Yang 2024-03-24 10:16:16 +08:00
parent 9fa4ed8633
commit f94438d9ef
7 changed files with 46 additions and 2 deletions

View File

@ -86,4 +86,9 @@ public @interface Column {
*/
Class<? extends TypeHandler> typeHandler() default UnknownTypeHandler.class;
}
/**
* 数据字段注释 AI 时代注释的内容往往可用于 AI 辅助对话
*/
String comment() default "";
}

View File

@ -50,4 +50,9 @@ public @interface Id {
*/
boolean before() default true;
}
/**
* 数据库字段注释 AI 时代注释的内容往往可用于 AI 辅助对话
*/
String comment() default "";
}

View File

@ -47,6 +47,11 @@ public @interface Table {
*/
String dataSource() default "";
/**
* 数据库表注释 AI 时代注释的内容往往可用于 AI 辅助对话
*/
String comment() default "";
/**
* 监听 entity insert 行为
*/

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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<InsertListener> 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())) {