3.gin(请求参数绑定)

1.ShouldBindQuery(获取GET)和ShouldBind(获取POST)

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
)

func main(){
	engine := gin.Default()
	engine.GET("/hello", func(context *gin.Context) {
		var student Student
		err := context.ShouldBindQuery(&student)
		if(err != nil){
			log.Fatal(err.Error())
			return
		}
		fmt.Println(student.Name)
		fmt.Println(student.Classes)
	})
	engine.Run()
}

type Student struct {
	Name string `form:"name"`
	Classes string `form:"classes"`
}

  

posted @ 2021-01-10 16:45  FinnYY  阅读(163)  评论(0编辑  收藏  举报