1.GET请求

最后更新于:2022-04-02 04:53:50

from表单get请求: ~~~ |-- routers | `-- router.go ~~~ ~~~ package routers import ( admin "project/admin/controllers" "github.com/astaxie/beego" ) func init() { // 固定路由也就是全匹配的路由 beego.Router("/admin/user/index", &admin.UserController{}, "*:Index") beego.Router("/admin/user/add", &admin.UserController{}, "*:Add") beego.Router("/admin/user/get_add", &admin.UserController{}, "*:GetAdd") } ~~~ ~~~ |-- admin | |--controllers | `-- user.go ~~~ ~~~ package admin import ( "fmt" "github.com/astaxie/beego" ) type UserController struct { beego.Controller } func (this *UserController) Index() { this.TplName = "admin/user/index.html" } func (this *UserController) GetAdd() { this.TplName = "admin/user/add.html" } func (this *UserController) Add() { // Get方式的请求,GetString 获取数据 var str string = this.GetString("get_string") this.Ctx.WriteString(fmt.Sprintf("get string : %s\n", str)) // Get方式的请求,GetStrings 获取数据 var strs []string = this.GetStrings("get_strings") this.Ctx.WriteString(fmt.Sprintf("get strings : %v\n", strs)) // Get方式的请求,GetInt 获取数据 int_ret, _ := this.GetInt("get_int") this.Ctx.WriteString(fmt.Sprintf("get int64 : %v\n", int_ret)) // Get方式的请求,GetBool 获取数据 bool_ret, _ := this.GetBool("get_bool") this.Ctx.WriteString(fmt.Sprintf("get bool : %v\n", bool_ret)) // Get方式的请求,GetFloat 获取数据 float_ret, _ := this.GetFloat("get_float") this.Ctx.WriteString(fmt.Sprintf("get float : %v\n", float_ret)) } ~~~ ~~~ |-- views | |--admin | |--user | `-- add.html ~~~ ~~~ admin/user/add this is admin/user/add
GetString:
GetStrings: GetStrings:
GetInt:
GetBool:
GetFloat:
~~~
';