Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Groovy on Grails

Groovy on Grails

Introduction to grails

Venkat Palivela

October 08, 2012
Tweet

More Decks by Venkat Palivela

Other Decks in Programming

Transcript

  1. INTRO TO GROOVY • Groovy is an agile and dynamic

    language for the JVM – Complies down to bytecode – But also supports static typing • Java on “steroids” – Builds upon the strengths of Java, but… – With powerful features borrowed from Smalltalk/Python/Ruby – Makes modern programming features available to Java developers.
  2. FROM JAVA TO GROOVY A Groovier program • Dynamic types

    using the def keyword • Everything is public unless defined otherwise • Automatic getters & setters • Semicolons at EOL are optional • Return keyword optional
  3. JOINT COMPILATION & TOTAL INTEROPERABILITY Java Class Groovy Class Java

    Interface Groovy Class Java Class Groovy Interface
  4. GROOVY OPERATORS! • Elvis Operator def value = something ?

    something : defaultValue def value = something ?: defaultValue • Safe Navigation Operator – Java: String postalCode = null; if(user != null){ Address address = user.getAddress(); if(address != null){ postalCode = address.getPostalCode(); if (postalCode != null) { postalCode = postalCode.toUpperCase(); } } } – Groovy: def postalCode = user?.address?.postalCode?.toUpperCase()
  5. FULL STACK FRAMEWORK • Controller layer based on Spring MVC

    • Dependency Injection using Spring Container • Transactional service layer based on Spring’s transaction abstraction. • View layer with Groovy Server Pages(GSP) • Embedded Tomcat servlet container for on the fly reloading.
  6. GRAILS COMMANDS grails create-app HelloWorld grails create-domain-class com.zix.HelloWorld grails create-controller

    com.zix.HelloWorld grails generate-all com.zix.HelloWorld grails run-app grails test-app grails war If desired, custom scripts with commands can be added to the project.
  7. PROJECT BREAKDOWN  grails-app  conf  controller  domain

     i18n  services  taglib  views  web-app  scripts  src  groovy  java  lib  test Top level source folder Configuration sources Controller Layer Model Layer Internationalization resources Service layer Dynamic Tag libraries Groovy Server Pages JavaScript, CSS Custom scripts Other sources Groovy projects Java projects 3rd Party libraries Unit, functional and integration tests