'Mastering Grails'에 해당되는 글 2

  1. 2009.04.10 [IBM dWs] Grails 마스터하기: GORM: 재미있는 이름, 진지한 기술
  2. 2009.03.06 [IBM dWs] Grails 마스터하기: 첫 번째 Grails 애플리케이션 구축하기

[IBM dWs] Grails 마스터하기: GORM: 재미있는 이름, 진지한 기술

- Grails 마스터하기: GORM: 재미있는 이름, 진지한 기술
- Mastering Grails: GORM: Funny name, serious technology

- 일대다 관계 만들기
Law of Leaky Abstractions, hasMany 설정, naked object pattern
class Trip{
    String name
    String city
    ...
    Airline airline //object composition
}

class Airline{
    static hasMany = [trip:Trip]
    ...
}
- PK가 노출되는 것을 막기 위해 toString()를 재정의
(이 방법 말고 다른 방법은 없나? 디버깅 때문에)

- static constraints
필드 순서 지정
데이터 유효성 검증(grails-app/i18n/messages.properties)

- GORM DSL
하이버네이트 HBM 매핑이나 어노테이션을 사용할 수도 있지만 Grails는 static mapping에서 한다.(naked-object 방식)
레거시 테이블 사용시 유용

- DataSource.groovy
새로운 환경을 추가할 수 있다.
dbCreate 설정(hibernate.hbm2ddl.auto)
    create-drop, create, update
데이터베이스 변경




[IBM dWs] Grails 마스터하기: 첫 번째 Grails 애플리케이션 구축하기

- Installation

- Sample
> grails create-app trip-planner
> cd trip-planner
> grails create-domain-class Trip
Add member variable to grails-app/domain/Trip.groovy
> grails generate-all Trip
> grails run-app

Browse to http://localhost:8080/trip-planner
- 포트 변경




- 동적 스캐폴딩
trip-planner/grails-app/controllers/TripController.groovy
class TripController{
    def scaffold = Trip
}
전체 코드 15줄(grails stats 로 확인가능)로 CRUD 기능을 처리하는 웹어플리케이션을 작성할 수 있다.

- 참고자료
IBM developerWorks : Grails 마스터하기
NetBeans : Introduction to the Grails Web Framework

[Grails1.0 사용자 가이드] 전체 목록
Grails Korean Home