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 ~~~ ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>admin/user/add</title> </head> <body> this is admin/user/add <form action='{{urlfor "UserController.Add"}}' method="post" enctype="multipart/form-data"> <div class="field-content"> PostString:<input name="post_string" type="text" /> </div> <div class="field-content"> PostStrings:<input name="post_strings" type="text" /> PostStrings:<input name="post_strings" type="text" /> </div> <div class="field-content"> PostInt:<input name="post_int" type="text" /> </div> <div class="field-content"> PostBool:<input name="post_bool" type="text" /> </div> <div class="field-content"> PostFloat:<input name="post_float" type="text" /> </div> <div class="field-content"> <input type="submit" value="提交" /> </div> </form> </body> </html> ~~~