> For the complete documentation index, see [llms.txt](https://lack.gitbook.io/learn-go/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lack.gitbook.io/learn-go/go-you-xiu-kuang-jia/go-webkuang-jia-gin/cha-xun-url-zhong-zi-fu-chuan-can-shu.md).

# 查询URL中字符串参数

**查询URL中字符串参数**

```go
func main() {
    router := gin.Default()

    // 访问路径：/welcome?firstname=Jane&lastname=Doe 输出 "Hello Jane Doe"
    router.GET("/welcome", func(c *gin.Context) {
        firstname := c.DefaultQuery("firstname", "Guest") // 默认参数
        lastname := c.Query("lastname") // 同等 c.Request.URL.Query().Get("lastname")

        c.String(http.StatusOK, "Hello %s %s", firstname, lastname)
    })
    router.Run(":8080")
}
```
