Create Domain Model
Last updated
Was this helpful?
Last updated
Was this helpful?
Example code is available on .
Grails documentation has nice description how to work with classes. In case you are new to Grails domain classes, you should definitelly read it.
Anyway, let's show an example how to create a domain object and use it in Vaadin application.
Run Grails create-domain
command that will create the new domain class Item
.
The generated and empty domain class Item.groovy
is in grails-app/domain/com/app
folder.
Before we start testing the domain class, we need to add there at least one field, for example, a string label
.
Domain object must be stored in
grails-app/domain
, contain at static fieldconstraints
to be considered as a valid domain object. Only then a database table for a domain object will be created.
Now, we need to create few records of Item
in the database during the application start-up.
Open BootStrap.groovy
and save few Item
instances there.
Use domain class to fetch all records from the database and display them in the browser.
Run the application and database records will be displayed in UI.