diff --git a/server/model/sys_auto_code.go b/server/model/sys_auto_code.go index 78b77778df5d1640d5124f2bd1c8c6cfe7815219..b8a3b524114d288c1d8d444ab597d8c7973ee214 100644 --- a/server/model/sys_auto_code.go +++ b/server/model/sys_auto_code.go @@ -4,14 +4,14 @@ import "errors" // 初始版本自动化代码工具 type AutoCodeStruct struct { - StructName string `json:"structName"` - TableName string `json:"tableName"` - PackageName string `json:"packageName"` - Abbreviation string `json:"abbreviation"` - Description string `json:"description"` - AutoCreateApiToSql bool `json:"autoCreateApiToSql"` - AutoMoveFile bool `json:"autoMoveFile"` - Fields []Field `json:"fields"` + StructName string `json:"structName"` + TableName string `json:"tableName"` + PackageName string `json:"packageName"` + Abbreviation string `json:"abbreviation"` + Description string `json:"description"` + AutoCreateApiToSql bool `json:"autoCreateApiToSql"` + AutoMoveFile bool `json:"autoMoveFile"` + Fields []*Field `json:"fields"` } type Field struct { diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index f8def744cdf56417af85271a51bc78691c9bb416..835b02bdef10c7cd60a985cf5840cfa7243cb126 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -320,6 +320,11 @@ func AutoCreateApi(a *model.AutoCodeStruct) (err error) { } func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) { + // 去除所有空格 + utils.TrimSpace(autoCode) + for _, field := range autoCode.Fields { + utils.TrimSpace(field) + } // 获取 basePath 文件夹下所有tpl文件 tplFileList, err := GetAllTplFile(basePath, nil) if err != nil { diff --git a/server/utils/file_operations.go b/server/utils/file_operations.go index 04b0413758597200176f1be5ec5d6fc18657f718..6963d9ecc3ea091cda667632129295163baf6710 100644 --- a/server/utils/file_operations.go +++ b/server/utils/file_operations.go @@ -3,6 +3,8 @@ package utils import ( "os" "path/filepath" + "reflect" + "strings" ) //@author: [songzhibin97](https://github.com/songzhibin97) @@ -39,3 +41,25 @@ Redirect: } return os.Rename(src, dst) } + +//@author: [songzhibin97](https://github.com/songzhibin97) +//@function: TrimSpace +//@description: 去除结构体空格 +//@param: target interface (target: 目标结构体,传入必须是指针类型) +//@return: err error + +func TrimSpace(target interface{}) { + t := reflect.TypeOf(target) + if t.Kind() != reflect.Ptr { + return + } + t = t.Elem() + v := reflect.ValueOf(target).Elem() + for i := 0; i < t.NumField(); i++ { + switch v.Field(i).Kind() { + case reflect.String: + v.Field(i).SetString(strings.TrimSpace(v.Field(i).String())) + } + } + return +}