app/views/App/index.html
<div class="span6"> {{template "flash.html" .}} <form action="/App/Hello" method="GET"> <input type="text" name="myName"/><br><br> <input type="submit" value="Say hello!"/> </form> </div>
app/controllers/app.go
func (c App) Hello(myName string) revel.Result { return c.Render(myName) }
conf/route
GET /App/Hello App.Hello
$ /home/vagrant/go/bin/revel run -a myapp
コンパイルし直す
http://192.168.34.10:9000/App/Hello?myName=test
### validation
func (c App) Hello(myName string) revel.Result { c.Validation.Required(myName).Message("Your name is required") c.Validation.MinSize(myName, 3).Message("Your name is not long enough!") if c.Validation.HasErrors(){ c.Validation.Keep() c.FlashParams() return c.Redirect(App.Index) } return c.Render(myName) }
<div class="span6"> {{template "flash.html" .}} <form action="/App/Hello" method="GET"> {{with $field := field "myName" .}} <input type="text" name="{{$field.Name}}" value="{{$field.Flash}}"/> {{end}} <br><br> <input type="submit" value="Say hello!"/> </form> </div>
OK, 後はMySQL連携