上下文
基本定义
gin封装的上下文对象。支持所有*gin.Context操作
最新api请参考,gin官网 https://github.com/gin-gonic/gin
操作常用
获取query参数
func(this *IndexController) Index(ctx *gin.Context) string {
ctx.DefaultQuery("firstname", "Guest")
ctx.Query("lastname")
return "this is 首页"
}ctx.Query("lastname") 相当于 ctx.Request.URL.Query().Get("lastname")
ctx.DefaultQuery("firstname", "Guest") 当firstname不存在时返回Guest,一般多用于分页 默认第一页
获取post参数
func(this *IndexController) Index(ctx *gin.Context) string {
message := ctx.PostForm("message")
nick := ctx.DefaultPostForm("nick", "anonymous")
return "this is 首页"
}获取上传文件
单文件上传
SaveUploadedFile 将文件移动到指定目标
多文件上传
将参数绑定到指定对象
获取cookie
写入cookie
最后更新于
这有帮助吗?