Using Groovy & Grails in your Spring Boot Project
-
Upload
spring-by-pivotal -
Category
Technology
-
view
1.624 -
download
2
Transcript of Using Groovy & Grails in your Spring Boot Project
Use Groovy & Grails in your Spring Boot projects,
don't be afraid!By Fátima Casaú
@fatimacasau
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 2
@fatimacasau
Fátima Casaú Pérez
Software Engineer since 8 years ago
Java Architect & Scrum Master in Paradigma Tecnológico
Specialized in Groovy & Grails environments
Recently, Spring Boot world
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3
What is Spring Boot?
What is Groovy?
Where could you use Groovy in your Spring Boot Projects?
● Gradle
● Tests
● Anywhere?
● Groovy Templates
● GORM
● GSP’s
Overview
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4
Spring Boot
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5
Standalone
Auto-configuration - CoC
No XML
Embedded Container and Database
Bootstrapping
Groovy!!
Run quickly - Spring Boot CLI
Spring Boot
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 6
Groovy
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7
Dynamic language
Optionally typed
@TypeChecked & @CompileStatic
Java Platform
Easy & expressive syntax
Powerful features
closures, DSL, meta-programming, functional programming, scripting, ...
Groovy
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8
Spring Boot application in a single tweet
DEMO...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 9
First, an useful tool!
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 10
GVMGroovy enVironment
Manager Tool
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11
GVM
Manage parallel versions
Multiple Software Development Kits
Groovy, Grails, Gradle, Spring Boot, Vert.x, Griffon,...
Unix Systems
Linux, Mac OSX, CyWin, Solaris,...
Bash
Curl & Unzip available
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 12
Actual candidates
GroovyGrailsGriffonGradleGroovyservLazybonesVert.xCrashGlideSpring BootAsciidoctorJ...
This list will grow beyond Groovy candidates.
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 13
How to use GVM and install SDK’s
To install GVM Tool
.bashrc
directory .gvm is created in home directory
$ curl -s get.gvmtool.net | bash
#THIS MUST BE AT THE END OF THE FILE FOR GVM TO WORK!!![[ -s "/home/fcasau/.gvm/bin/gvm-init.sh" ]] && source "/home/fcasau/.gvm/bin/gvm-init.sh"
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 14
How to use GVM and install SDK’s
Useful commands$ gvm help$ gvm install springboot$ gvm list springboot$ gvm install springboot 1.2.5.RELEASE$ gvm use grails 2.5.0$ gvm default groovy 2.4.0$ gvm current$ gvm current gradle$ gvm uninstall grails 2.4.4$ gvm broadcast
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15
HelloWorld.groovy
1 @RestController2 class HelloWorld {3 4 @RequestMapping("/")5 String home(){6 "*** Hello World ***"7 }8 9 10 11 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 16
But... what happens
behind?
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17
HelloWorld.groovy
1 2 3 4 5 6 7 8 @RestController9 class HelloWorld {10 11 @RequestMapping("/")12 String home(){13 "***************** Hello World *******************"14 }15 16 17 18 19 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 18
HelloWorld.groovy
1 @Grab(group='org.springframework.boot:spring-boot-starter-web')2 3 import org.springframework.boot.SpringApplication4 import org.springframework.web.bind.annotation.*5 import org.springframework.boot.autoconfigure.*6 7 @EnableAutoConfiguration(exclude = GroovyTemplateAutoConfiguration)8 @RestController9 class HelloWorld {10 11 @RequestMapping("/")12 String home(){13 "***************** Hello World *******************"14 }15 16 static void main(String[] args){17 SpringApplication.run HelloWorld, args18 }19 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19
Executing...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20
Where could you use
groovy?
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 21
Gradle
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 22
Powerful build tool
Support multi-project
Dependency management (based on Apache Ivy)
Support and Integration with Maven & Ivy repositories
Based on Groovy DSL
Build by convention
Ant tasks
Gradle
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 23
Building a Spring Boot app with Gradle
DEMO...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24
Install Gradle and create a Spring Boot project
$ mkdir -p springOne2gx/src/main/groovy$ touch springOne2gx/src/main/groovy/Application.groovy$ cd springOne2gx$ touch build.gradle
Edit build.gradle and Application.groovy with the code of the next two slides
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25
build.gradle
1 buildscript {2 repositories {3 maven { url "https://repo.spring.io/libs-release" }4 mavenLocal()5 mavenCentral()6 }7 dependencies {8 classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")9 }10 }11 12 apply plugin: 'groovy'13 apply plugin: 'idea'14 apply plugin: 'spring-boot'15 16 jar {17 baseName = 'springOne2GX'18 version = '0.1.0'19 }20 21 repositories {22 maven { url "https://repo.spring.io/libs-release" }23 mavenLocal()24 mavenCentral()25 }26 27 dependencies {28 compile("org.springframework.boot:spring-boot-starter-web")29 compile "org.codehaus.groovy:groovy-all:2.2.0"30 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 26
Application.groovy
1 import org.springframework.boot.SpringApplication2 import org.springframework.boot.autoconfigure.SpringBootApplication3 4 @SpringBootApplication5 class Application {6 7 static void main(String[] args) {8 9 SpringApplication.run Application, args10 }11 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 27
Executing...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 28
Testing with Spock
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 29
Spock framework & specification
Expressive
Groovy DSL’s
Easy to read tests
Well documented
Powerful assertions
Reports
Testing with Spock
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 30
Testing with Spock
DEMO...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 31
GoogleSpec.groovy
1 void "test Google Maps API where address is ‘Madrid’"(){2 setup: “Google Maps API Host & Uri” 3 def rest = new RESTClient("https://maps.googleapis.com")4 def uri = "/maps/api/geocode/json"5 when: “Call the API with address = ‘madrid’”6 def result = rest.get(path: uri, query: [address:'madrid'])7 then: “HttpStatus is OK, return a list of results and field status = OK”8 result9 result.status == HttpStatus.OK.value()10 !result.data.results.isEmpty()11 result.data.status == ‘OK’12 result.data.results[0].address_components.any{13 it.long_name == 'Madrid'14 }15 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 32
GoogleSpec.groovy
1 void "test Google Maps API with different values"(){2 setup: “Google Maps API Host & Uri”3 def rest = new RESTClient("https://maps.googleapis.com")4 def uri = "/maps/api/geocode/json"5 6 expect: “result & status when call the REST API”7 def result = rest.get(path: uri, query: [address:address])8 resultsIsEmpty == result.data.results.isEmpty()9 result.data.status == status10 11 where: “address takes different values with different results & status”12 address | resultsIsEmpty | status13 'Madrid'| false | 'OK'14 'abdkji'| true | 'ZERO_RESULTS'15 '186730'| false | 'ZERO_RESULTS' // This fails!16 17 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 33
Condition not satisfied:
result.data.status == status| | | | || | OK | ZERO_RESULTS| | false| | 11 differences (8% similarity)| | (---)O(K-------)| | (ZER)O(_RESULTS)| [results:[[address_components:[[long_name:186730, short_name:186730, types:[postal_code]], [long_name:Russia, short_name:RU, types:[country, political]]], formatted_address:Russia, 186730, geometry:[bounds:[northeast:[lat:61.84356, lng:30.2495827], southwest:[lat:61.4653021, lng:30.0576869]], location:[lat:61.67159349999999, lng:30.1745203], location_type:APPROXIMATE, viewport:[northeast:[lat:61.84356, lng:30.2495827], southwest:[lat:61.4653021, lng:30.0576869]]], place_id:ChIJt3ErZ3qEmUYRPW2d-LubWzA, types:[postal_code]]], status:OK]groovyx.net.http.HttpResponseDecorator@5f5f6fd6
Assertions
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 34
Reports
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 35
dependencies { testCompile("org.springframework.boot:spring-boot-starter-test") testCompile("org.springframework:spring-test") testRuntime("org.spockframework:spock-spring:0.7-groovy-2.0") { exclude group: 'org.spockframework', module: 'spock-core' } testCompile("org.spockframework:spock-core:0.7-groovy-2.0") { exclude group: 'org.codehaus.groovy', module: 'groovy-all' } … }
Dependencies
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 36
● Simple Spring Boot Application with Spock Test:● https://github.com/tomaslin/gs-spring-boot-spock
● Documentation: ● http://docs.spockframework.org
More information
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 37
Executing...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 38
Anywhere!!
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 39
Anywhere
Mix Java & Groovy easily
More expressive, simple & flexible than Java
Less code → less errors → more productivity
Extension of JDK -> GDK
@CompileStatic @TypeChecked
Domain classes, Controllers, Repositories,...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 40
Groovy domain, repository and controller
DEMO...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 41
Customer.groovy
1 import javax.persistence.*2 3 @Entity4 public class Customer {5 6 @Id7 @GeneratedValue(strategy= GenerationType.AUTO)8 long id;9 String firstName;10 String lastName;11 12 @Override13 String toString() {14 "Customer[id=$id, firstName=$firstName, lastName=$lastName"15 }
Domain class
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 42
Repository
CustomerRepository.groovy
1 import com.paradigma.springOne2gx.Customer2 import org.springframework.data.repository.CrudRepository3 import org.springframework.data.rest.core.annotation.RepositoryRestResource4 5 import java.util.List6 7 @RepositoryRestResource(collectionResourceRel = "customers", path = "customer")8 public interface CustomerRepository extends CrudRepository<Customer, Long> {9 10 List<Customer> findByLastName(@Param(value = "lastName") String lastName)11 12 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 43
Controllers
CustomerController.groovy
1 import org.springframework.beans.factory.annotation.Autowired2 import org.springframework.stereotype.Controller3 import org.springframework.web.bind.annotation.*4 5 @Controller6 public class CustomerController {7 8 @Autowired9 CustomerRepository customerRepository10 11 @RequestMapping("/customer/{id}")12 @ResponseBody13 public Customer findById(@PathVariable Long id) {14 return customerRepository.findOne(id)15 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 44
Adding customers in Application.groovy
1 @SpringBootApplication2 class Application {3 4 static void main(String[] args) {5 6 ConfigurableApplicationContext context = SpringApplication.run(Application.class)7 8 CustomerRepository repository = context.getBean(CustomerRepository.class)9 10 // save a couple of customers11 [[firstName:"Rachel Karen", lastName:"Green"],[firstName:"Monica E.", lastName:"Geller"],12 [firstName:"Phoebe", lastName:"Buffay"],[firstName:"Joey", lastName:"Tribbiani"],13 [firstName:"Ross", lastName:"Geller"],[firstName:"Chandler Muriel", lastName:"Bing"]].each {14 repository.save(new Customer(it)) 15 }16 17 // print all customers18 def customers = repository.findAll()19 println "Customers found with findAll():"20 customers.each { println it }21 22 // find a customer by ID23 Customer customer = repository.findOne(1L)24 println "Customer found with findOne(1L): $customer"25 26 // find customers by last name27 def lastName = "Bing"28 customers = repository.findByLastName(lastName)29 println "Customer found with findByLastName('$lastName'):"30 customers.each { println it }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 45
dependencies { compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-data-jpa")compile("com.h2database:h2")
… }
Dependencies
More information & exampleshttps://spring.io/guides/gs/accessing-data-jpa/
https://spring.io/guides/gs/accessing-data-rest/
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 46
Executing...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 47
Groovy Templates
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 48
Groovy Template Framework
Based MarkupBuilder
Groovy DSL’s
Render readable views
Replace variables easily
Layouts
Groovy Templates
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 49
Groovy templates
DEMO...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 50
list.tpl
1 layout 'layouts/main.tpl',2 pageTitle: 'List customers',3 mainBody: contents {4 ul {5 customers.each { customer ->6 li {7 p("$customer.firstName $customer.lastName ")8 }9 }10 }11 div{12 a(href:"/", "Go to home")13 }14 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 51
dependencies { compile("org.springframework.boot:spring-boot-starter-groovy-templates") … }
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-groovy-templates
Spring Projects Example
Dependencies
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 52
Executing...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 53
GORM
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 54
Automatic mapping for entities
Dynamic finders, criterias, persistence methods, validation, mappings,
constraints…
Expressive and simple code
implicit getters & setters
implicit constructors
implicit primary key
For Hibernate
For MongoDB
Grails Object Relational Mapping
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 55
GORM in Spring Boot
DEMO...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 56
Customer.groovy
1 import grails.persistence.*2 3 @Entity4 public class Customer {5 6 @Id7 @GeneratedValue(strategy= GenerationType.AUTO)8 long id;9 String firstName;10 String lastName;11 12 @Override13 String toString() {14 "Customer[id=$id, firstName=$firstName, lastName=$lastName"15 }
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 57
1 // lines in application main class2 3 [[firstName:"Rachel Karen", lastName:"Green"],4 [firstName:"Monica E.", lastName:"Geller"],5 [firstName:"Chandler Muriel", lastName:"Bing"]].each {6 new Customer(it).save()7 }8 9 def customers = Customer.list() // implicit method list()10 customers.each {11 println it12 }13 14 Customer customer = Customer.get(1L) // implicit method get(...)15 println "Customer found with get(1L): $customer"16 17 def lastName = "Bing"18 customers = Customer.findAllByLastName(lastName)19 // implicit methods findAllBy... findBy...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 58
dependencies { compile("org.grails:gorm-hibernate4-spring-boot:1.1.0.RELEASE") compile("com.h2database:h2") … }
Dependencies
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 59
Executing...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 60
GSP's
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 61
Groovy Server Pages is used by Grails
Large list of useful Tag Libraries
Easy to define new Tags
Not only views
Layouts & Templates
Reuse Code
Groovy Server Pages
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 62
GSP's in Spring Boot
Some code...
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 63
<g:if test="${session.role == 'admin'}"> <%-- show administrative functions --%></g:if><g:else> <%-- show basic functions --%></g:else>
<g:each in="${[1,2,3]}" var="num"> <p>Number ${num}</p>
</g:each>
<g:findAll in="${books}" expr="it.author == 'Stephen King'"> <p>Title: ${it.title}</p>
</g:findAll>
<g:dateFormat format="dd-MM-yyyy" date="${new Date()}" />
<g:render template="bookTemplate" model="[book: myBook]" />
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 64
dependencies { compile("org.grails:grails-gsp-spring-boot:1.0.0") compile("org.grails:grails-web-gsp:2.5.0") compile("org.grails:grails-web-gsp-taglib:2.5.0") compile("org.grails:grails-web-jsp:2.5.0") … }
Dependencies
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 65
Conclusions
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 66
If you use Groovy…
Less code → Less errors → More productivity
GDK → More features → Cool utilities
Spock → Cool Tests
Super-vitaminized project!!
Why use Groovy?
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 67
That's all
THANKS!!