Groovy & Grails

4,446 views

Published on

groovy and grails

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,446
On SlideShare
0
From Embeds
0
Number of Embeds
195
Actions
Shares
0
Downloads
144
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Groovy & Grails

  1. 1. Groovy & Grails Rain 2010-1-15
  2. 2. 目录 <ul><li>Groovy </li></ul><ul><li>Grails </li></ul><ul><li>Demo </li></ul>
  3. 3. Web Frameworks
  4. 4. How do we choose?
  5. 5. Grails vs Rails <ul><li>Groovy vs Ruby </li></ul><ul><li>API documentation better than Rails </li></ul><ul><li>Solid frameworks underneath, such as spring, hibernate </li></ul><ul><li>Both has a active community, Rails more popular, and more jobs, more books. </li></ul>
  6. 6. Grails vs Rails <ul><li>DB Migrations </li></ul><ul><li>GORM vs Active Record </li></ul><ul><li>REST </li></ul><ul><li>Webserver </li></ul><ul><li>Faster than Rails, but used lot of memory, cheaper hosting </li></ul><ul><li>Rails mature than Grails </li></ul><ul><li>Rails release/update more often </li></ul>
  7. 7. Groovy <ul><li>Groovy 是一种基于 JVM 的敏捷开发语言,它结合了 Python 、 Ruby 和 Smalltalk 的许多强大的特性。 </li></ul><ul><li>支持 DSL </li></ul><ul><li>对于 Java 开发人员几乎没有学习难度 </li></ul><ul><li>可以编译成字节码 </li></ul>
  8. 8. Hello Groovy <ul><li>def name='World'; println &quot;Hello $name!&quot; </li></ul>
  9. 9. Groovy vs Java <ul><li>default imports </li></ul><ul><li>closures </li></ul><ul><li>native syntax for lists and maps </li></ul><ul><li>GroovyMarkup and GPath support </li></ul><ul><li>native support for regular expressions </li></ul><ul><li>polymorphic iteration and powerful switch statement </li></ul><ul><li>dynamic and static typing is supported - so you can omit the type declarations on methods, fields and variables </li></ul><ul><li>you can embed expressions inside strings </li></ul><ul><li>lots of new helper methods added to the JDK </li></ul><ul><li>simpler syntax for writing  beans for both properties and adding event listeners </li></ul><ul><li>safe navigation using the ?. operator, e.g. &quot;variable?.field&quot; and &quot;variable?.method()&quot; - no more nested ifs to check for null clogging up your code </li></ul>
  10. 10. Default imports <ul><li>java.io.* </li></ul><ul><li>java.lang.* </li></ul><ul><li>java.math.BigDecimal </li></ul><ul><li>java.math.BigInteger </li></ul><ul><li>java.net.* </li></ul><ul><li>java.util.* </li></ul><ul><li>groovy.lang.* </li></ul><ul><li>groovy.util.* </li></ul>
  11. 11. Commons <ul><li>int[] a = {1,2,3}; -> int[] a = [1,2,3] </li></ul><ul><li>for (int i=0; i < len; i++) {...} </li></ul><ul><li>-> for (i in 0..len-1) {...} </li></ul><ul><li>-> len.times {...} </li></ul>
  12. 12. Others to know <ul><li>Semicolons are optional </li></ul><ul><li>You can use the this keyword inside static methods </li></ul><ul><li>The return keyword is optional </li></ul><ul><li>The throws clause in a method signature is not checked by the Groovy compiler </li></ul><ul><li>You will not get compile errors like you would in Java for using undefined members or passing arguments of the wrong type. </li></ul>
  13. 13. Cloure <ul><li>square = { it * it } </li></ul><ul><li>square(9) // 81 </li></ul><ul><li>[ 1, 2, 3, 4 ].collect(square) // =[ 1, 4, 9, 16 ] </li></ul>
  14. 14. Grails <ul><li>快速 Web 开发框架 </li></ul><ul><li>基于 Groovy 编程语言 </li></ul><ul><li>构建于 Spring 、 Hibernate 和其它标准 Java 框架之上 </li></ul><ul><li>高效的一站式框架 </li></ul>
  15. 16. Success Stories
  16. 17. MVC <ul><li>Model : Domain </li></ul><ul><li>class Person { </li></ul><ul><li>String name </li></ul><ul><li>} </li></ul><ul><li>View : gsp 、 taglib </li></ul><ul><li>Controller : XxxController </li></ul><ul><li>class PersonController { </li></ul><ul><li>def create = {} </li></ul><ul><li>def save = {} </li></ul><ul><li>def view = {} </li></ul><ul><li>} </li></ul>
  17. 18. Scaffold <ul><li>class XxxController { </li></ul><ul><ul><li>def scaffold = Domain </li></ul></ul><ul><li>} </li></ul>
  18. 19. GORM <ul><li>CRUD : save 、 get 、 delete 、 list </li></ul><ul><li>findBy* </li></ul><ul><li>findAllBy* </li></ul><ul><li>findWhere </li></ul><ul><li>findAllWhere </li></ul><ul><li>find(sql) </li></ul><ul><li>count/countBy* </li></ul><ul><li>exists </li></ul><ul><li>list/listOrderBy </li></ul><ul><li>withCriteria </li></ul><ul><li>executeQuery(HSQL) </li></ul>
  19. 20. Taglib <ul><li>if/else/elseif/while/set/collect/each/grep/findAll </li></ul><ul><li>meta/header/cookie </li></ul><ul><li>pageProperty/layoutHeader/layoutTitle/layoutBody/applyLayout </li></ul><ul><li>resource/javascript/include/render </li></ul><ul><li>textField/textArea/radio/checkBox/form/ </li></ul><ul><li>remoteField/formRemote/remoteLink </li></ul>
  20. 21. Service <ul><li>在 grails-app/service 目录 </li></ul><ul><li>命名约定 XxxService </li></ul>
  21. 22. Testing <ul><li>unit </li></ul><ul><li>Integration </li></ul><ul><li>GroovyTestCase </li></ul><ul><li>GrailsUnitTestCase </li></ul><ul><li>GroovyPagesTestCase </li></ul><ul><li>ControllerUnitTestCase </li></ul><ul><li>TagLibUnitTestCase </li></ul><ul><li>WebFlowTestCase </li></ul>
  22. 23. Plugins <ul><li>Over 340 </li></ul><ul><li>Security : Acegi 、 Shiro </li></ul><ul><li>Ajax : Prototype 、 jQuery 、 YUI 、 GWT </li></ul><ul><li>UI : GrailsUI 、 RichUI </li></ul><ul><li>Report : Dynamic Jasper </li></ul><ul><li>Jobs : Quartz </li></ul><ul><li>Web 2.0: Feeds 、 Taggable 、 Commentable </li></ul><ul><li>Workflow : grailsflow 、 jbpm </li></ul><ul><li>Editor : FCKeditor </li></ul>
  23. 24. Tools <ul><li>IDE: Eclipse 3.5 、 NetBeans 6.8 、 IDEA 9 、 Spring STS 2.3.0 </li></ul><ul><li>Editor : E-Texteditor 、 Textmate 、 GEdit </li></ul><ul><li>Build : Maven 、 Ant 、 Ivy </li></ul><ul><li>WebContainer : Tomcat 、 Jetty </li></ul><ul><li>Database : HSQL 、 MySQL </li></ul><ul><li>GRAG </li></ul>
  24. 25. Books
  25. 26. Tutorials <ul><li>Mastering Grails @ IBM developerWorks </li></ul><ul><li>Cookbook Tutorials </li></ul><ul><li>Articles </li></ul><ul><ul><li>Twitter and Google Maps mashup in 20 minutes with Grails </li></ul></ul><ul><ul><li>Securing a Grails application using Spring and Acegi Security </li></ul></ul><ul><ul><li>A Grails-Powered Blog (Part 1) </li></ul></ul><ul><ul><li>A Grails-Powered Blog (Part 2) </li></ul></ul>
  26. 27. Presentations <ul><li>http://grailspodcast.com/blog/list </li></ul><ul><li>Grails JavaOne 2006 Slides </li></ul><ul><li>Groovy & Grails Seminar </li></ul><ul><li>Bending GORM: 5-minute Techniques for Enterprise Integration </li></ul><ul><li>Grails 1.1 Testing - Unit, Integration, Functional (July 2009) </li></ul><ul><li>Getting Started with Grails </li></ul>
  27. 28. Roadmap <ul><li>Grails 1.3 </li></ul><ul><li>support groovy 1.7 , standalone GSP , Deployment and resolution of plugins from Maven repositories </li></ul><ul><li>Grails 2.0 </li></ul><ul><li>modular deployment with OSGi </li></ul>
  28. 29. App <ul><li>grails.org </li></ul><ul><li>http://grails.org </li></ul><ul><li>groovyblogs.org </li></ul><ul><li>http://www.groovyblogs.org/ </li></ul><ul><li>Weceem CMS </li></ul><ul><li>http://www.weceem.org/ </li></ul><ul><li>Groller </li></ul><ul><li>http://code.google.com/p/rainboyan/ </li></ul>
  29. 30. Demo <ul><li>Grails HelloWorld: </li></ul><ul><li>1) grails create-app helloworld </li></ul><ul><li>2) grails create-controller hello </li></ul><ul><li>3) edit HelloController.groovy </li></ul><ul><li>4) create say.gsp </li></ul><ul><li>5) grails run-app </li></ul>
  30. 31. Links <ul><li>http://www.grails.org </li></ul><ul><li>http://www.grails.org/Tutorials </li></ul><ul><li>http://www.jtict.com/blog/grails-vs-rails/ </li></ul><ul><li>http://www.grails.org/GRAG </li></ul>
  31. 32. QA <ul><li>? </li></ul>

×