From 43fa2d76abc7230a00f0e3095471ba83864b03b4 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Thu, 26 Mar 2020 18:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=20model=20curd=E5=88=9D=E6=AD=A5=E5=AE=8C?= =?UTF-8?q?=E5=B7=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QMPlusServer/model/autoCodeModel/autoCode.go | 18 ++++++------- QMPlusServer/tpl/te/struct.go.tpl | 27 ++++++++++++++----- .../src/view/superAdmin/autoCode/index.vue | 3 +++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/QMPlusServer/model/autoCodeModel/autoCode.go b/QMPlusServer/model/autoCodeModel/autoCode.go index dd2cf8d7..bd9cb182 100644 --- a/QMPlusServer/model/autoCodeModel/autoCode.go +++ b/QMPlusServer/model/autoCodeModel/autoCode.go @@ -2,7 +2,6 @@ package autoCodeModel import ( "fmt" - log "gin-vue-admin/init/initlog" "html/template" "os" ) @@ -55,27 +54,28 @@ func Temp() { ComponentDictionary: nil, } a := AutoCodeStruct{ - StructName: "Test", - PackageName: "autocode", - Components: []Component{a1, a2}, + StructName: "Test", + PackageName: "autocode", + Abbreviation: "t", + Components: []Component{a1, a2}, } _dir := "../" + a.PackageName exist, err := pathExists(_dir) if err != nil { - log.L.Info("get dir error![%v]\n", err) + //log.L.Info(fmt.Sprintf("get dir error![%v]\n", err)) return } if exist { - log.L.Info("has dir![%v]\n", _dir) + //log.L.Info(fmt.Sprintf("has dir![%v]\n"+_dir)) } else { - log.L.Info("no dir![%v]\n", _dir) + //log.L.Info(fmt.Sprintf("no dir![%v]\n"+_dir)) // 创建文件夹 err := os.Mkdir(_dir, os.ModePerm) if err != nil { - log.L.Error("mkdir failed![%v]\n", err) + //log.L.Error(fmt.Sprintf("mkdir error![%v]\n",err)) } else { - log.L.Info("mkdir success!\n") + //log.L.Info("mkdir success!\n") } } file, err := os.OpenFile("../"+a.PackageName+"/struct.go", os.O_CREATE|os.O_WRONLY, 0755) diff --git a/QMPlusServer/tpl/te/struct.go.tpl b/QMPlusServer/tpl/te/struct.go.tpl index 29014100..47a74c81 100644 --- a/QMPlusServer/tpl/te/struct.go.tpl +++ b/QMPlusServer/tpl/te/struct.go.tpl @@ -6,7 +6,6 @@ import ( "gin-vue-admin/init/qmsql" "gin-vue-admin/model/modelInterface" "github.com/jinzhu/gorm" - "github.com/pkg/errors" ) type {{.StructName}} struct { @@ -15,22 +14,38 @@ type {{.StructName}} struct { } // 创建{{.StructName}} -func ({{.Abbreviation}} *{{StructName}})Create{{.StructName}}()(err error){ +func ({{.Abbreviation}} *{{.StructName}})Create{{.StructName}}()(err error){ err = qmsql.DEFAULTDB.Create({{.Abbreviation}}).Error return err } // 删除{{.StructName}} -func ({{.Abbreviation}} *{{StructName}})Delete{{.StructName}}()(err error){ +func ({{.Abbreviation}} *{{.StructName}})Delete{{.StructName}}()(err error){ err = qmsql.DEFAULTDB.Delete({{.Abbreviation}}).Error return err } // 更新{{.StructName}} -func ({{.Abbreviation}} *{{StructName}})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){ - +func ({{.Abbreviation}} *{{.StructName}})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){ + err = qmsql.DEFAULTDB.Save({{.Abbreviation}}).Error + return err, *{{.Abbreviation}} } -func ({{.Abbreviation}} *{{StructName}})Create(){ +// 根据ID查看单条{{.StructName}} +func ({{.Abbreviation}} *{{.StructName}})FindById()(err error,re{{.Abbreviation}} {{.StructName}}){ + err = qmsql.DEFAULTDB.Where("id = ?",{{.Abbreviation}}.ID).First(&re{{.Abbreviation}}).Error + return err,re{{.Abbreviation}} +} +// 分页获取{{.StructName}} +func ({{.Abbreviation}} *{{.StructName}})GetInfoList(info modelInterface.PageInfo)(err error, list interface{}, total int){ + // 封装分页方法 调用即可 传入 当前的结构体和分页信息 + err, db, total := servers.PagingServer({{.Abbreviation}}, info) + if err != nil { + return + } else { + var re{{.StructName}}List []{{.StructName}} + err = db.Find(&re{{.StructName}}List).Error + return err, re{{.StructName}}List, total + } } \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue b/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue index dfa172eb..67056cb4 100644 --- a/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue +++ b/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue @@ -7,6 +7,9 @@ + + +