beego路由匹配(记录)

beego

路由匹配

beego.Router(“/api/?:id”,&controllers.RController{})
—————————————————————————————————————————————————————
http://localhost:8080/user/dds?id=2
dd1:=c.Ctx.Input.Param(":id")//获取dds
dd2:=c.Ctx.Input.Query("id")//获取2

数据绑定

支持从用户请求中直接数据 bind 到指定的对象,例如请求地址如下

?id=123&isok=true&ft=1.2&ol[0]=1&ol[1]=2&ul[]=str&ul[]=array&user.Name=astaxie
var id int
this.Ctx.Input.Bind(&id, "id")  //id ==123

var isok bool
this.Ctx.Input.Bind(&isok, "isok")  //isok ==true

var ft float64
this.Ctx.Input.Bind(&ft, "ft")  //ft ==1.2

ol := make([]int, 0, 2)
this.Ctx.Input.Bind(&ol, "ol")  //ol ==[1 2]

ul := make([]string, 0, 2)
this.Ctx.Input.Bind(&ul, "ul")  //ul ==[str array]

user struct{Name}
this.Ctx.Input.Bind(&user, "user")  //user =={Name:"astaxie"}

猜你喜欢

转载自blog.csdn.net/a976134036/article/details/78876191
今日推荐