diff --git a/imp/ContentGenerate.go b/imp/ContentGenerate.go index 57e2029..6108000 100644 --- a/imp/ContentGenerate.go +++ b/imp/ContentGenerate.go @@ -6,5 +6,5 @@ type ContentGenerate interface { /* 内容制造接口 */ - GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string) string + GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string, string string) string } diff --git a/reverse/Engine.go b/reverse/Engine.go index dc5669f..793a1bf 100644 --- a/reverse/Engine.go +++ b/reverse/Engine.go @@ -154,9 +154,9 @@ func dbReverse(path string, tableName string, dbName string, db *sql.DB) { if nil == cms { log.Println("没有查到数据库字段信息略过") } - fms, hasTime := buildFieldMessage(cms) //创建字段名和类型的映射 - w := bufio.NewWriter(file) //进行文件的操作 - content := cg.GenerateFileContent(path, tableName, fms, hasTime, tagKey) //拼go文件 + fms, hasTime := buildFieldMessage(cms) //创建字段名和类型的映射 + w := bufio.NewWriter(file) //进行文件的操作 + content := cg.GenerateFileContent(path, tableName, fms, hasTime, tagKey, tableComment) //拼go文件 _, err := w.WriteString(content) checkError(err, "写入出错了:") fErr, cErr := w.Flush(), file.Close() diff --git a/support/FileContentSupport.go b/support/FileContentSupport.go index 5bc51d0..d328551 100644 --- a/support/FileContentSupport.go +++ b/support/FileContentSupport.go @@ -8,13 +8,14 @@ import ( type FileContentSupport struct{} -func (FileContentSupport) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string) string { +func (FileContentSupport) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string, tableComment string) string { var build strings.Builder pName := splitLast(filePath, static.Splice) - writePackage(&build, pName) //写文件的引用包 - writeImportIfTime(&build, hasTime) //如果有time.Time类型的需要写入import - buildStructHead(&build, fileName) //写入结构体头 + writePackage(&build, pName) //写文件的引用包 + writeImportIfTime(&build, hasTime) //如果有time.Time类型的需要写入import + writeTableComment(&build, tableComment) //写入表注释 + buildStructHead(&build, fileName) //写入结构体头 //对于没有字段的返回空定义的文件 if len(fms) == 0 { @@ -99,3 +100,10 @@ func splitLast(filePath string, split string) string { ss := strings.Split(filePath, split) return ss[len(ss)-1] } + +func writeTableComment(builder *strings.Builder, s string) { + if s != "" { + builder.WriteString("//" + s) + builder.WriteString("\n") + } +} diff --git a/support/FileContentSupport2.go b/support/FileContentSupport2.go index 60f041d..edb4aeb 100644 --- a/support/FileContentSupport2.go +++ b/support/FileContentSupport2.go @@ -7,7 +7,7 @@ import ( type FileContentSUpport2 struct{} -func (FileContentSUpport2) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string) string { +func (FileContentSUpport2) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string, string string) string { fmt.Println("12321321") return " " }