Grails 2.0.4(二)

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 目录

5.  如果不能跑,那么就改下

demo\grails-app\conf\BuildConfig.groovy

 

把第36行 // runtime 'mysql:mysql-connector-java:5.1.16' 注释去掉

让程序在run-app自动下载jar

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值