Leverages Hibernate but minus .hbm files and other messy configuration files
Provides dynamic domain class methods like...
create
save
delete
update
get
find
findAll
addTo
count
....
Relationships
One to one
One to many (hasMany)
Many to many
Demo
Domain Classes Demo
Controllers
Manages requests and response for domain objects
Unless overridden, maps requests to a REST-like structure /<domain class>/action_name
It's actions can be generated on the fly by the application
Groovy Server Pages
Provide views for domain objects
Like JSP, GSPs can be a mix of markup, Groovy code and GSP tags*
Generally correspond to an associated action in the controller
Code fragments use the <% %> and <%= %> forms, though this is discouraged
Typical GSP
<html>
<body>
<% [1,2,3,4].each { num -> %>
<p><%="Hello ${num}!" %></p>
<%}%>
</body>
</html>
Taglibs
Allow the developer to simplify blocks of code
Similar to JSP tag libs class SimpleTagLib { def emoticon = { attrs, body -> out << body() << attrs.happy == 'true' ? " :-)" : " :-(" } }
Can be declared at an application or plugin level (e.g. Grails Chart plugin)
Taglibs in the wild
<html>
<body>
<g:emoticon happy='true'>
</body>
</html>
Demo
Controllers and GSP Demo
Databases
Grails supports almost all JDBC compliant databases
grails-app/conf/Datasources.groovy allows you to specify datasources for different env's
0 comments
Post a comment