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.

50 lines
1.7 KiB

  1. // 自动生成模板{{.StructName}}
  2. package {{.PackageName}}
  3. import (
  4. "gin-vue-admin/controller/servers"
  5. "gin-vue-admin/init/qmsql"
  6. "gin-vue-admin/model/modelInterface"
  7. "github.com/jinzhu/gorm"
  8. )
  9. type {{.StructName}} struct {
  10. gorm.Model {{range .Fields}}
  11. {{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}"{{if .ColumnName}} gorm:"column:{{.ColumnName}}"{{end}}`{{ end }}
  12. }
  13. // 创建{{.StructName}}
  14. func ({{.Abbreviation}} *{{.StructName}})Create{{.StructName}}()(err error){
  15. err = qmsql.DEFAULTDB.Create({{.Abbreviation}}).Error
  16. return err
  17. }
  18. // 删除{{.StructName}}
  19. func ({{.Abbreviation}} *{{.StructName}})Delete{{.StructName}}()(err error){
  20. err = qmsql.DEFAULTDB.Delete({{.Abbreviation}}).Error
  21. return err
  22. }
  23. // 更新{{.StructName}}
  24. func ({{.Abbreviation}} *{{.StructName}})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){
  25. err = qmsql.DEFAULTDB.Save({{.Abbreviation}}).Error
  26. return err, *{{.Abbreviation}}
  27. }
  28. // 根据ID查看单条{{.StructName}}
  29. func ({{.Abbreviation}} *{{.StructName}})FindById()(err error,re{{.Abbreviation}} {{.StructName}}){
  30. err = qmsql.DEFAULTDB.Where("id = ?",{{.Abbreviation}}.ID).First(&re{{.Abbreviation}}).Error
  31. return err,re{{.Abbreviation}}
  32. }
  33. // 分页获取{{.StructName}}
  34. func ({{.Abbreviation}} *{{.StructName}})GetInfoList(info modelInterface.PageInfo)(err error, list interface{}, total int){
  35. // 封装分页方法 调用即可 传入 当前的结构体和分页信息
  36. err, db, total := servers.PagingServer({{.Abbreviation}}, info)
  37. if err != nil {
  38. return
  39. } else {
  40. var re{{.StructName}}List []{{.StructName}}
  41. err = db.Find(&re{{.StructName}}List).Error
  42. return err, re{{.StructName}}List, total
  43. }
  44. }