<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## Beego-Go語言在開發過程遇到一些小問題匯總 在開發過程中經常會遇見一些問題,現把匯總和解決方法記錄一下。 1、session設置的問題 在設置session的時候,有整型,有字符串類型,在連接的時候要用到: fmt.Sprintf() + 連接字符串,不格式一下,直接拼接會報錯 ~~~ this.SetSession("userLogin", fmt.Sprintf("%d", users.Id)+"||"+users.Username+"||"+users.Avatar) ~~~ 2、session獲取問題 在設置好session后,獲取的是通過 ~~~ this.GetSession("userLogin") ~~~ 如果userLogin的值是整型的話,不會報錯;如果按上面的(第一條),整型與字符串拼接,會報錯可以采用: ~~~ this.GetSession("userLogin").(string) ~~~ .(string)有多種類型,如果獲取session報錯的時候,根據自己的實際情況換成.(int)等 **在非Controller中操作Session** ~~~ import ( ? ?"github.com/astaxie/beego/context" ) var FilterAdmin = func(ctx *context.Context) { ctx.Input.CruSession.Get("userLogin") ? ? ? ? ? ?//讀取Session ctx.Input.CruSession.Set("userLogin","yes") ? ?//設置Session ctx.Input.CruSession.Delete("userLogin") ? ? ? ? //刪除Session } ~~~ 3、長整型轉換問題 數字長整型字符串轉換成長整型,可以先轉換成整型,再轉成長整型如: ~~~ userid, _ := strconv.Atoi(tmp[0]) longid := int64(userid) ~~~ 4、長整型數字返回給前端JS,數值溢出問題 在提交或其它操作的時候,經常會返回json格式的給前端,對于長整型的數字,js處理會溢出 在返回的長整型值必須fmt.Sprintf("%d",id)格式化處理一下,這樣前端JS就不用處理~ ~~~ this.Data["json"] = map[string]interface{}{"code": 1, "message": "項目信息添加成功", "id": fmt.Sprintf("%d", id)} ~~~ 5、字符串分割成map 在項目中經常會處理一些如“lock,tom,jerry,李白”,現在想把轉換成map: ~~~ names := strings.Split("6565243443941654055,4365243443941654055,1454243443941654055,1465243443941654034", ",") var namesmap = make(map[int]int64) for i, v := range ccids { ? names, _ := strconv.Atoi(v) ? namesmap[i] = int64(names) } fmt.Println(namesmap) ~~~ 6、多條件傳遞參數,查詢在model里經常會寫一些通用的方法,會根據不同的條件進行SQL搜索 ~~~ condArr := make(map[string]string) condArr["projectid"] = idstr condArr["status"] = status condArr["type"] = stype ~~~ 在方法中傳遞condArr就可以了,方法的定義可能是這樣 ~~~ func ListProjectTask(condArr map[string]string, page int, offset int) (num int64, err error, ops []ProjectsTask) { ? } ~~~ 7、Beego分頁 要引用: ~~~ "github.com/astaxie/beego/utils/pagination" ~~~ 具體如下: ~~~ countTask := CountTask(condArr) paginator := pagination.SetPaginator(this.Ctx, offset, countTask) _, _, tasks := ListProjectTask(condArr, page, offset) this.Data["tasks"] = tasks this.Data["paginator"] = paginator ~~~ 用beego開發服務端應用:[https://www.cnblogs.com/zhangboyu/p/7760693.html](https://www.cnblogs.com/zhangboyu/p/7760693.html) beego入門文檔:[https://blog.csdn.net/zdyueguanyun/article/details/52916481](https://blog.csdn.net/zdyueguanyun/article/details/52916481)
                  <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>

                              哎呀哎呀视频在线观看