You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB

// 自动生成模板{{.StructName}}
package {{.PackageName}}
import (
"gin-vue-admin/controller/servers"
"gin-vue-admin/init/qmsql"
"gin-vue-admin/model/modelInterface"
"github.com/jinzhu/gorm"
)
type {{.StructName}} struct {
gorm.Model {{range .Fields}}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}"{{if .ColumnName}} gorm:"column:{{.ColumnName}}"{{end}}`{{ end }}
}
// 创建{{.StructName}}
func ({{.Abbreviation}} *{{.StructName}})Create{{.StructName}}()(err error){
err = qmsql.DEFAULTDB.Create({{.Abbreviation}}).Error
return err
}
// 删除{{.StructName}}
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}}){
err = qmsql.DEFAULTDB.Save({{.Abbreviation}}).Error
return err, *{{.Abbreviation}}
}
// 根据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
}
}