grails部署开发


参考:The Grails Framework - Reference Documentation  网址:http://itrc.jju.edu.cn/1.1/guide/single.html#7.1%20Declaring%20Constraints

1  启动IntelliJ IDEA时候,如果出现:


SEVERE: Problems copying method. Incompatible JVM?
java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source),则是由于Grails 不支持 JDK 1.8 版本。修改JDK为1.7即可。

2 CSVN在Windows上执行部署

(1)grails prepare
(2)需要配置console\target\dist\data\conf\httpd.conf中
ServerRoot "E:\svnedge\console\target\dist"

配置路径,在target/dist/data/conf/httpd.conf的顶层目录下,创建服务,名字为CollabNet Subversion Apache
cmd下运行为




httpd.exe -k install -n "CollabNet Subversion Server" -f "target\dist\data\conf\httpd.conf",其中找到httpd.exe,可以对其target\dist\data\conf\httpd.conf目录根据路径进行修改。

target\dist\bin\httpd.exe -k install -n "CollabNet Subversion Server" -f "data\conf\httpd.conf"

如果该服务运行失败,打开cmd,输入sc delete  CollabNetSubversionServer 删除该服务,可以去services.msc进行查看。


 withTransaction 用来处理事务

def transferFunds = {
        Account.withTransaction { status ->
                def source = Account.get(params.from)
                def dest = Account.get(params.to)

def amount = params.amount.toInteger() if(source.active) { source.balance -= amount if(dest.active) { dest.amount += amount } else { status.setRollbackOnly() } }

}

}

如果目的账户没有处于活动状态,系统将回滚事务,同时如果有任何异常抛出在事务的处理过程中也将会自动回滚。

4 constraints验证或者约束

class User {
    String login
    String password
    String email
    Integer age

static constraints = {

login(size:5..15, blank:false, unique:true) //login属性必须在5-15个字符长度之间,不能为空,并且必须是唯一的

password(size:5..15, blank:false)

email(email:true, blank:false) age(min:18, nullable:false) } }


5  Many-to-Many

class Book {
   static belongsTo = Author
   static hasMany = [authors:Author]
   String title
}
class Author {
   static hasMany = [books:Book]
   String name
}

Grails在数据库层使用一个连接表来映射many-to-many,在这种情况下,Author 负责持久化关联,并且是唯一可以级联保存另一端的一方 。

例如,下面这个可以进行正常级联保存工作:

new Author(name:"Stephen King")
                .addToBooks(new Book(title:"The Stand"))
                .addToBooks(new Book(title:"The Shining"))           
                .save()

而下面这个只保存 Book而不保存 authors!

new Book(name:"Groovy in Action")
                .addToAuthors(new Author(name:"Dierk Koenig"))
                .addToAuthors(new Author(name:"Guillaume Laforge"))             
                .save()


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值