I have a form similar to this one in Grails:
Name: _____
Age: _____
Street: _____
Email: ____
|S开发者_开发问答ubmit|
How can i pass all the filled in information to a controller that will add me the records to the database? Im kinda new to Grails, and my problem is i dont understand how to "pass" and get things to the controllers.
class Person {
String name
Integer age
String street
String email
}
class PersonController {
def save = {
def personInstance = new Person(params)
personInstance.save(flush:true)
}
}
<g:form controller="person" action="save">
<g:textField name="name" />
<g:textField name="age" />
<g:textField name="street" />
<g:textField name="email" />
<g:submitButton name="save" value="Save" />
</g:form>
Also, if you have a domain, you can run
grails generate-all com.foo.Person
And all the code will be generated for you. Then you can see how it is done.
精彩评论