查询字符串

未匹配的标注

获取URL参数

与其它框架不同,Iris 的url查询字符串并不是显性路由一部分,它隐式由请求对象发起,如下所示

func main() {
    app := iris.Default()

    // 查询字符串参数用在隐式的请求对象上,被传递
    // 请求匹配字符串:  /welcome?firstname=Jane&lastname=Doe.
    app.Get("/welcome", func(ctx iris.Context) {
        firstname := ctx.URLParamDefault("firstname", "Guest")
        // 使用 ctx.Request().URL.Query().Get("lastname")调用方法的快捷方式
        lastname := ctx.URLParam("lastname") 

        ctx.Writef("Hello %s %s", firstname, lastname)
    })

    app.Run(iris.Addr(":8080"))
}

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
pardon110
讨论数量: 0
发起讨论 只看当前版本


暂无话题~