gin中获取查询字符串参数

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()
	r.GET("/", func(context *gin.Context) {
		id := context.Query("id")  // context.Request.URL.Query().Get("id") 的一种快捷方式
		name := context.DefaultQuery("name", "默认值")
		context.String(http.StatusOK, "id=%s, name=%s", id, name)
	})
	r.Run()
}

  

posted @ 2021-10-27 14:55  专职  阅读(168)  评论(0编辑  收藏  举报