Grails 2.0.4(二)

2983 ワード

1.Airlineクラスを追加
  static constraints  

 
class Airline { 
   static mapping = {
    table 'some_other_table_name'
    columns {
      name column:'airline_name'
      url column:'link'
      frequentFlyer column:'ff_id'
    }
  }
   static constraints = {
    name(blank:false, maxSize:100)   //  
    url(url:true)
    frequentFlyer(blank:true)
    notes(maxSize:1500)  
  }
  String name
  String url
  String frequentFlyer
  String notes
  String toString(){
    return name
  }
 }

 2. TripクラスにAirlineプロパティを追加する
 
class Trip { 
  String name
  String city
  ...
  Airline airline
}

 3. generate-all demo.Airline
     generate-all demo.Trip
 
 4.grails-app/conf/DataSource.groovyをMySQLに変更
 
dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = "root"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost:3306/test?autoreconnect=true"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost:3306/test?autoreconnect=true"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost:3306/test?autoreconnect=true"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

データベースを作成し、ドライバJARをlibディレクトリにコピー
[原句]走れないなら、やめる
demo\grails-app\conf\BuildConfig.groovy
 
36行目//runtime'mysql:mysql-connector-java:5.1.16'コメントを削除
プログラムをrun-appでjarを自動的にダウンロードさせる