2.POST请求

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

from表单post请求: ~~~ |-- 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) Add() { // this.Ctx.Request.Method 获取请求方式 if this.Ctx.Request.Method == "GET" { this.TplName = "admin/user/add.html" } else { // Post方式的请求,GetString 获取数据 var str string = this.GetString("post_string") this.Ctx.WriteString(fmt.Sprintf("post string : %s\n", str)) // Post方式的请求,GetStrings 获取数据 var strs []string = this.GetStrings("post_strings") this.Ctx.WriteString(fmt.Sprintf("post strings : %v\n", strs)) // Post方式的请求,GetInt 获取数据 int_ret, _ := this.GetInt("post_int") this.Ctx.WriteString(fmt.Sprintf("post int64 : %v\n", int_ret)) // Post方式的请求,GetBool 获取数据 bool_ret, _ := this.GetBool("post_bool") this.Ctx.WriteString(fmt.Sprintf("post bool : %v\n", bool_ret)) // Post方式的请求,GetFloat 获取数据 float_ret, _ := this.GetFloat("post_float") this.Ctx.WriteString(fmt.Sprintf("post float : %v\n", float_ret)) } } ~~~ ~~~ |-- views | |--admin | |--user | `-- add.html ~~~ ~~~ admin/user/add this is admin/user/add
PostString:
PostStrings: PostStrings:
PostInt:
PostBool:
PostFloat:
~~~
';