我是 gin-gonic 框架的新手,我一直在嘗試從 html 的 get 請求中添加的輸入中讀取值,但我無法讀取我編寫的值。當我提交請求時,瀏覽器發送此網址: http://localhost:3000/backend?name1=value1&name2=value2&name3=value3我一直在互聯網上查找 gin-gonic 使用此 url 類型的地方,但我只發現它使用像這樣的 url http://localhost:3000/backend/value1html代碼:<!DOCTYPE html><html><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>戈蘭代碼:package mainimport("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"}
- 1 回答
- 0 關注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消