This document provides an introduction to Grails, a full-stack web application framework for Groovy and Java. It discusses how to install Grails, its architecture and philosophy, and demonstrates creating a sample Grails application with a Person domain class. Key aspects covered include the Grails command line interface, domain classes, controllers, views, services, testing, and plugins.
4. FULL STACK FRAMEWORK
ORM (GORM)
Powerfulview technology(GSP) and easyTagLib creation
DependencyInjection and on-the-flyreloading(Spring)
Internationalization support(i18n)
Runtime Container (Tomcat)
TestingFramework (Spock)
Plugin System
Command line tools
Build Tool(Gant/Gradle)
and abunch of other stuff…
17. DON'T LET FRIENDS FORK
Open:
/grails-app/conf/BuildConfig.groovy
Change:
grails.project.fork=[
//configuresettingsforcompilationJVM,notethatifyoualtertheGroovyversion
...
...
//configuresettingsfortheConsoleUIJVM
console:[maxMemory:768,minMemory:64,debug:false,maxPerm:256]
]
To:
grails.project.fork=false
18. DOMAIN
/grails-app/domain/
The M in MVC
Gets mapped to the database
Dynamic finders FTW -> ForgetSQL
constraintsenforce database consistency
Defines scaffolded views
20. MY FIRST DOMAIN CLASS
$grailscreate-domain-classPerson
//grails-app/domain/Person.groovy
classPerson{
Stringname
Integerage
staticconstraints={
nameblank:false
agemin: 0
}
}
21. SAVE AND VALIDATE
constraintsare enforced on save()and validate()
defperson=newPerson(age:42,name:'DouglasAdams')
person.validate()//onlychecksconstraints
person.save()//savestheinstancetothedatabase
22. WHOLE LOTTA DYNAMIC GOIN’ ON
Finders are dynamicallycreated for allproperties
defeverybody=Person.list()
deftheOne=Person.findByNameAndAge('Brian',41)
defcaseInsensitive=Person.findAllByNameIlike('graeme')
defunderAge=Person.findAllByAgeLessThan(18)
defseniors=Person.findAllByAgeGreaterThanEquals(65)
deforderedByName=Person.listOrderByName()
51. LETS ADD A NEW FEATURE
Person should have country
//grails-app/domain/Person.groovy
classPerson{
Stringname
Integerage
Stringcountry
staticconstraints={
nameblank:false
age min:0
countrynullable:true
}
}