Learn Java for Web Development

(Tina Meador) #1
CHAPTER 7: Rapid Web Development with Grails 321

Creating a Domain Class

At this point, the application we created doesn’t really do anything; it just renders a simple textual
response. We will move on by creating a domain class. To create a domain class, use the Grails
create-domain-class target. This creates a new Grails domain class in the grails-app/domain
directory, as well as a unit test for the domain class in test/unit.


To create the Book domain class, you need to execute the create-domain-class target using an
optional class name, as shown here:



grails create domain-class book



If you don’t supply the class name, you are prompted for one.


Notice that when running the create-domain-class target with the optional class name, you can
leave the class name in lowercase, and Grails will automatically uppercase it for you so that it follows
the standard Groovy class naming convention.


To create the domain class using GGTS, click “domain” in the project hierarchy and then use
New ➤ Domain Class, as illustrated in Figure 7-19.


Figure 7-18. Test report: failed test

Free download pdf