mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 19:09:57 +08:00
docs(readme): add BindQuery section.
This commit is contained in:
parent
08c0c222cf
commit
eafa073f71
37
README.md
37
README.md
@ -454,7 +454,42 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bind Query String
|
### Only Bind Query String
|
||||||
|
|
||||||
|
`BindQuery` function only binds the query params and not the post data. See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-315953017).
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
Name string `form:"name"`
|
||||||
|
Address string `form:"address"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
route := gin.Default()
|
||||||
|
route.Any("/testing", startPage)
|
||||||
|
route.Run(":8085")
|
||||||
|
}
|
||||||
|
|
||||||
|
func startPage(c *gin.Context) {
|
||||||
|
var person Person
|
||||||
|
if c.BindQuery(&person) == nil {
|
||||||
|
log.Println("====== Only Bind By Query String ======")
|
||||||
|
log.Println(person.Name)
|
||||||
|
log.Println(person.Address)
|
||||||
|
}
|
||||||
|
c.String(200, "Success")
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Bind Query String or Post Data
|
||||||
|
|
||||||
See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-264681292).
|
See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-264681292).
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user