package main
import (
"fmt"
"net/http"
"reflect"
"strings"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("defaultQuery", defaultQuery)
r.Run()
}
func defaultQuery(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"id_": c.DefaultQuery("id", "100"),
"name_": c.Query("name"),
})
}
如果不传参数id
,那么将使用默认值
http://localhost:8080/defaultQuery?name=张三