gin的控制器:
          type ExampleService struct { UserName String Password String } func (example
          *ExampleService) LoginCheck(c *gin.Context) bool { c.Bind(&example)
          ............ }前端應(yīng)該寫:this.axios.post("login.html", { UserName: this.username,
          //這里對應(yīng)struct的成員名 Password: this.password })
          還有一種更輕量靈活的寫法:

          func LoginCheck(c *gin.Context) bool { var param struct { Username string
          `json:"username" binding:"required"` Password string `json:"password"
          binding:"required"` } c.Bind(¶m) ............................
          前端照舊




          劃重點(diǎn): 結(jié)構(gòu)體成員變量名首字母必須大寫!!!




          補(bǔ)充:

          當(dāng)綁定的成員為int或者int32,int64類型時,前端如果傳入的值為0,會報如下錯誤:

          [GIN-debug] [WARNING] Headers were already written. Wanted to override status
          code 400 with 200


          且前端會報錯誤:Failed to load resource: the server responded with a status of 400
          (Bad Request)

          導(dǎo)致不正常.

          解決辦法1: 避免設(shè)計(jì)0值;

          解決辦法2: 去掉以下結(jié)構(gòu)體的 binding:"required"



          var json struct { ????????Status int64 `json:"status" binding:"required"`
          ????} ????c.Bind(&json)



          友情鏈接
          ioDraw流程圖
          API參考文檔
          OK工具箱
          云服務(wù)器優(yōu)惠
          阿里云優(yōu)惠券
          騰訊云優(yōu)惠券
          京東云優(yōu)惠券
          站點(diǎn)信息
          問題反饋
          郵箱:[email protected]
          QQ群:637538335
          關(guān)注微信

                好大好涨水好多好想要 | 亚洲综合成人电影 | 久久成人影音 | 欧美激情老妇胡秀英最爽的一次 | 欧美丰满做爰XXXⅩVV69 |