Ich bin neu zu gehen und erleben Sie BEGO.Kann gebuchte Formulardaten nicht von BEGO analysieren
Ich versuche, die Formulareingaben aus zu erhalten:
<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>
Zur Steuerung:
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, "/")
}
Aber statt die Zeichenfolge-Werte in das Feld eingegeben, erhalte ich:
Your note title is %!s(*string=0xc82027a368)
Your note body is %!s(*string=0xc82027a378)
Ich folgte the docs auf Anfrage Verarbeitung, aber links ahnungslos, warum nicht die gepostete str iings.
Sie sind die Zeiger-Adressen bekommen, was ist, wenn Sie log.Printf ändern ("Ihre Anmerkung Titel% s", & n.Title) Dafür -> log.Printf ("Dein Notiztitel ist% s", n.Titel) – chespinoza
Dann bekomme ich Sachen wie 'Dein Notiztitel ist 0xc820267d18' – Karlom
Aber, überprüfend die Dokumentation die Möglichkeit die Struktur zu definieren (in deinem Fall Note) ist als ein Struct-Typ nicht als ein Zeiger (&) auf diese Struktur, dann in Ihrem Code sollten Sie sein n: = Hinweis {} – chespinoza