0
我是新來的,經歷蜜蜂。無法解析來自beego的發佈表單數據
我試圖讓從提交的表單數據:
<form action="/hello" method="post">
{{.xsrfdata}}
Title:<input name="title" type="text" /><br>
Body:<input name="body" type="text" /><br>
<input type="submit" value="submit" />
</form>
到控制器:但
type HelloController struct {
beego.Controller
}
type Note struct {
Id int `form:"-"`
Title string `form:"title"`
Body string `form:"body"`
}
func (this *HelloController) Get() {
this.Data["xsrfdata"]= template.HTML(this.XSRFFormHTML())
this.TplName = "hello.tpl"
}
func (this *HelloController) Post() {
n := &Note{}
if err := this.ParseForm(&n); err != nil {
s := err.Error()
log.Printf("type: %T; value: %q\n", s, s)
}
log.Printf("Your note title is %s" , &n.Title)
log.Printf("Your note body is %s" , &n.Body)
this.Ctx.Redirect(302, "/")
}
不是字符串值輸入到現場,我得到:
Your note title is %!s(*string=0xc82027a368)
Your note body is %!s(*string=0xc82027a378)
我按照the docs的要求處理,但是左無知爲什麼不能貼出str英格斯。
你所得到的指針地址,大約如果你改變log.Printf( 「你的筆記標題爲%s」,&n.Title)什麼爲此 - > log.Printf(「你的筆記標題是%s」,n.Title) – chespinoza
然後我得到像'你的筆記標題是0xc820267d18' – Karlom
但是,檢查文檔的方式來定義結構(在你的情況注意)作爲一個結構類型而不是指向該結構的指針(&),那麼在你的代碼中你應該是n:= Note {} – chespinoza