是否需要 gin-gonic 支持?

Does gin-gonic support get request?

我是 gin-gonic 框架的新手,我一直在尝试从 html 的获取请求中添加的输入中读取值,但我无法读取我输入的值写了。

当我提交请求时,浏览器发送此 url: http://localhost:3000/backend?name1=value1&name2=value2&name3=value3

我一直在网上寻找 gin-gonic 使用这种 url 类型的地方,但我只发现它像这样使用 url http://localhost:3000/backend/value1

html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <form method="GET" action="/backend">
        <input id="store" name="name1" type="text">
        <input id="razon" name="name2" type="text">
        <input id="total" name="name3" type="text">
        <input type="submit" value="submit">
    </form>
</body>
</html>

golang代码:

package main

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

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

router.Use(static.Serve("/",static.LocalFile("./views",true)))

router.GET("/backend",func(c *gin.Context){
    fmt.Println(c.Param("name1"))
    c.JSON(http.StatusOK, gin.H{
        "name1" : c.Param("name1"),
    })
})


router.Run(":3000")
}

实际结果: {"name1":""}

预期结果: {"name1":"value1"}

您要查找的函数不是Param(),而是Query()

https://github.com/gin-gonic/gin#querystring-parameters