Professional Documents
Culture Documents
Groovy & Grails Tutorial: Developer Tutorials Ver 1.0
Groovy & Grails Tutorial: Developer Tutorials Ver 1.0
Developer Tutorials
ver 1.0
rubengerad@gmail.com
Topics
Groovy Language
GroovyBeans
Closures
GString
Collections
Ranges
Categories
Builders
MetaProgramming
Grails Framework
Grails Services
GROOVY Language
GROOVY Language
Switch statement supports all types.
Last
def
x evaluated expression is the return values, does not
require
return statement
def
doSomething(param1){
x = param1}
Groovy Language
def x = [a, c, b, d]
x.sort()
x.reverse()
def num = 2
num.toString();
stringDate = "2015-01-01"
dateArray = stringDate.tokenize("-")
year = dateArray[0].toInteger()
year = year + 1
newDate = year + "-" + dateArray[1] + "-" + dateArray[2]
GStrings
Groovy Beans
Closures
Collection
Groovy provides native support for List, Set, Map and
array.
Lists
can= be
def
mylist
[ 1,evaluated
2, 3, 4 ] as Boolean to check if it is empty
Collection
Categories
Categories are more like friend functions which can be
used inside the context of other classes with loose
coupling.
sortIt(mylist){//implementation}
}
@Category
class LinearSort{
sortIt(mylist){//implementation}
}
class Sorter{
def sortIt(type,list){
switch(type){
case BUBBLE:
use(BubbleSort){ list.sortIt();} break
case LINEAR: use(LinearSort){ list.sortIt();} break
default: use(BubbleSort){ list.sortIt();}
}
Builders
Meta programming
Grails Framework
Grails is a full stack framework and attempts to solve as
many pieces of the web development puzzle through the
core technology and it's associated plug-ins. Included out
the box are things like:
Grails Application
A Grails application is
generated not created.
The basic structure is
generated on providing
the create-app command.
It provides a ready to use
application development
environment
configured
for the developers.
Use a modern IDE like
netbeans and create a
groovy
project
which
executes
the
same
command internally to
build the empty project
structure.
Grails Application
A Grails application is
generated not created.
The basic structure is
generated on providing
the create-app command.
It provides a ready to use
application development
environment
configured
for the developers.
Use a modern IDE like
netbeans and create a
groovy
project
which
executes
the
same
command internally to
build the empty project
structure.
Grails Services
//Command line method
grails create-service
com.attinad.tutorials.service.Employee
package com.attinad.tutorials.service
import grails.transaction.Transactional
@Transactional
class EmployeeService {
static scope = session
def serviceMethod() {
}
THANK YOU!