<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ### **根據下圖創建模型文件** ![](https://img.kancloud.cn/72/d8/72d8d3e65ed0c5aaaeb2af23b157f7d0_314x196.png) baseModel.go //是基礎模型 (為了實現模型之間的繼承 處理一下公共方法) ~~~ package models import ( "github.com/gin-gonic/gin" ) type BaseModel struct { } // **********************以下代碼可以不用要******************************* type Paginate struct { Page int `form:"page" json:"page"` Limit int `form:"limit" json:"limit"` Offset int `form:"offset" json:"offset"` } func (BaseModel) ExecutePage(ctx *gin.Context) *Paginate { var paginate Paginate if ctx.ShouldBind(&paginate) == nil { paginate.Offset = (paginate.Page - 1) * paginate.Limit } return &paginate } ~~~ staff.go ~~~ package models import ( "github.com/gin-gonic/gin" "learn_gin/common" "learn_gin/db" "strconv" ) // Staff 結構體封裝字段 type Staff struct { BaseModel Id int `json:"id"` Status int `json:"status"` InfoId int `json:"info_id"` Nickname string `json:"nickname"` Account string `json:"account"` Password string `json:"password"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` } // TableName 該模型鏈接的數據表名 func (Staff) TableName() string { return "staff" } // Condition 搜索條件 func (Staff)Condition(ctx *gin.Context) string { where := "1=1" nickname := ctx.DefaultQuery("nickname","") account:= ctx.DefaultQuery("account","") status:= ctx.DefaultQuery("status","") if status != ""{ where += " AND `status` = " + status } if nickname != ""{ where += " AND `nickname` like " + status + "%" } if account != ""{ where += " AND `account` like " + account + "%" } return where } // List 查詢列表 func(Staff) List(condition string,page Paginate) map[string]interface{} { var result []Staff //result := make([]models.Staff, 0) var total int64 if page.Limit != 0 || page.Offset != 0{ db.DB.Table("staff").Where(condition).Limit(page.Limit).Offset(page.Offset).Find(&result) db.DB.Table("staff").Where(condition).Limit(page.Limit).Offset(page.Offset).Count(&total) }else{ db.DB.Table("staff").Where(condition).Find(&result) db.DB.Table("staff").Where(condition).Count(&total) } data := make(map[string]interface{}) data["data"] = result data["total"] = total return data } // Insert 數據添加 func (Staff) Insert(ctx *gin.Context) { //data := &Staff{} var data Staff status ,_ := strconv.ParseInt(ctx.PostForm("status"),10,8) infoId,_ := strconv.ParseInt(ctx.PostForm("info_id"),10,8) data.Status = int(status) data.Nickname = ctx.PostForm("nickname") data.Account = ctx.PostForm("nickname") data.InfoId = int(infoId) data.Password = common.Md5(ctx.PostForm("password")) data.CreatedAt = common.GetDate() data.UpdatedAt = common.GetDate() db.DB.Table("staff").Create(&data) } func (Staff) Update(ctx *gin.Context) { var data Staff staffId := ctx.DefaultQuery("staff_id","") status ,_ := strconv.ParseInt(ctx.PostForm("status"),10,8) infoId,_ := strconv.ParseInt(ctx.PostForm("info_id"),10,8) where := "`id` = " + staffId password := ctx.DefaultQuery("password","") if password != ""{ password = common.Md5(password) } data.Status = int(status) data.Nickname = ctx.PostForm("nickname") data.Account = ctx.PostForm("nickname") data.InfoId = int(infoId) data.Password = password data.UpdatedAt = common.GetDate() db.DB.Table("staff").Where(where).Updates(&data) } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看