grails service用法

scope

默认service是单例的,可以通过scope改变:

(1)prototype:每次注入到其它类中时,都新建一个service实例

(2)request:会为每次请求创建一个service

(3)flash:会为当前和下一次请求创建一个service

(4)flow:In web flows the service will exist for the scope of the flow

(5)conversation:In web flows the service will exist for the scope of the conversation.

(6)session:为每个用户session创建一个service实例

(7)singleton:默认。

class BookService {
	static scope = "session"
	…
}

transactional

默认service是没有自动事物管理的。通过设置transactional=true,可以使用其中的方法都支持spring的事务管理,默认是PROPAGATION_REQUIRED。

class BookService {
    static transactional = true
	…
}

 

最后欢迎大家访问我的个人网站:1024s​​​​​​​

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值