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

Grails 3で生まれ変わったGrailsの今 / Spring in Summer 2015

Kazuki YAMAMOTO
September 02, 2015
400

Grails 3で生まれ変わったGrailsの今 / Spring in Summer 2015

「Spring in Summer ~ 夏なのにSpring」での発表資料です

http://www.springframework.jp/summer

Kazuki YAMAMOTO

September 02, 2015
Tweet

Transcript

  1. Grailsͱ͸ • Graeme Rocherࢯ͕։ൃ • ϑϧελοΫͷWebϑϨʔϜϫʔΫ • Groovyϕʔε • Ruby

    on RailsɺDjangoͱ͍ͬͨϑϨʔϜϫʔΫʹӨڹΛड͚͍ͯΔ • DRYʢDon't Repeat Yourselfʣ= ಉ͡هड़Λ܁Γฦ͞ͳ͍ • CoCʢConvention over Configurationʣ= ઃఆΑΓ΋ن໿ • εΩϟϑΥϧσΟϯά • Java EE্Ͱಈ࡞
  2. Grailsͷྺ࢙    4QSJOH4PVSDF഑Լ΁  7.XBSF͕ 4QSJOH4PVSDFΛങऩ  

     4QSJOH4PVSDF͕ 1JWPUBM഑Լ΁    1JWPUBMଔۀ
  3. Ϗϡʔ(GSP) <!DOCTYPE html>
 <html>
 <head>
 <meta name="layout" content="main"/>
 <title>Render Domain</title>


    </head>
 <body>
 <table>
 <tr>
 <td>Name</td>
 <td>Age</td>
 </tr>
 <g:each in="${list}" var="person">
 <tr>
 <td>${person.lastName}, ${person.firstName}</td>
 <td>${person.age}</td>
 </tr>
 </g:each>
 </table>
 </body>
 </html>
  4. υϝΠϯΫϥε(GORM) class Book {
 String title
 Integer price
 
 static

    constraints = {
 title(blank: false, maxSize: 20)
 price(min: 0)
 }
 }
 
 // 保存
 new Book(title: "はじめてのGrails", price: 3000).save()
 
 // クエリ
 Book.list()
 Book.findByTitle("はじめてのGrails")
  5. ςετ(Spock) @TestFor(Book)
 class BookSpec extends Specification {
 def "find book

    by title"() {
 given: "Bookが1件保存"
 new Book(title: "test title", price: 3000).save()
 
 when: "Bookをタイトルで検索する"
 def book = Book.findByTtile("test title")
 
 then: "対象のBookが取得できている"
 book.title == "test title"
 book.price == 3000
 }
 }
  6. Spring Boot • Spring Boot 1.2Λϕʔεʹ࠶ߏங • ಺෦ΞϓϦέʔγϣϯαʔό • ࣮ߦՄೳJarϑΝΠϧ

    • Spring Boot΍SpringͷΤίγεςϜ͕ΑΓ׆༻͠΍͘͢ • ϞχλϦϯάͷ֦ு౳ • Spring CloudΛ࢖͍͍ͨ౳
  7. application.yml ---
 grails:
 profile: web
 codegen:
 defaultPackage: grails.sample.plugin.database.migration
 info:
 app:


    name: '@info.app.name@'
 version: '@info.app.version@'
 grailsVersion: '@info.app.grailsVersion@'
 spring:
 groovy:
 template:
 check-template-location: false
 
 ---
 grails:
 mime:
 disable:
 accept:
 header:

  8. buildscript {
 ext {
 grailsVersion = project.grailsVersion
 }
 repositories {


    mavenLocal()
 maven { url "https://repo.grails.org/grails/core" }
 }
 dependencies {
 classpath "org.grails:grails-gradle-plugin:$grailsVersion"
 classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.1.1'
 classpath 'org.grails.plugins:database-migration:2.+'
 }
 }
 
 plugins {
 id "io.spring.dependency-management" version "0.4.0.RELEASE"
 }
 
 version "0.1"
 group "grails.sample.plugin.database.migration"
 
 apply plugin: "spring-boot"
 apply plugin: "war"
 apply plugin: "asset-pipeline"
 apply plugin: 'eclipse'
 apply plugin: 'idea'
 apply plugin: "org.grails.grails-web"

  9. Logback͕σϑΥϧτʹ appender('STDOUT', ConsoleAppender) {
 encoder(PatternLayoutEncoder) {
 pattern = "%level %logger

    - %msg%n"
 }
 }
 
 root(ERROR, ['STDOUT'])
 logger('org.hibernate.type.descriptor.sql.BasicBinder', TRACE)
 logger('org.hibernate.SQL', DEBUG)
  10. Geb͕σϑΥϧτϓϥάΠϯʹ @Integration
 class HomeSpec extends GebSpec {
 
 void "Test

    the home page renders correctly"() {
 when:"The home page is visited"
 go '/'
 
 then:"The title is correct"
 $('title').text() == "Welcome to Grails"
 }
 }
  11. Grails 3ͷ࣮ࡍ • Grails 2.x͔ΒͷҠߦ͸͍ͨ΁Μ • υΩϡϝϯτͱҠߦϓϥάΠϯͰؤுΔ • Grails 3Ͱͳ͘ͳͬͨػೳ͕͕͋ͬͨඞཁͳػೳ͸෮׆

    • ίϛϡχςΟ͔ΒͷϑΟʔυόοΫ • ϓϥάΠϯ͕গͳ͍ • ओཁͳϓϥάΠϯ͸ग़ἧ͍ͭͭ͋Δ • Spring Security Plugin΋ઌ೔M1͕ϦϦʔε • ·ͩόάଟΊͳؾ΋ • ΄ΜͱΜͲͷ৔߹͸ϫʔΫΞϥ΢ϯυ͸ଘࡏ͢Δ
  12. ࠓޙͷϦϦʔε༧ఆ • Grails 3.1 • New feature planned include: •

    More flexible profile repository support • multiple repositories • custom repositories • altering current repo • REST Improvements • REST profile • JSON builder views • Renderer convention • Removal of org.json and GSon to unify around JsonBuilder • Namespaced marshallers • UrlMappings for members and collections • AngularJS / SPA framework support • AngularJS profile https://github.com/grails/grails-core/wiki/Roadmap