制造控制器交易控制器 [英] Make controller Transactional controller

查看:126
本文介绍了制造控制器交易控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中,我有一个更新2域类的动作。



我希望它以这样的方式创建,如果第二次更新失败,返回,基本上如果有错误,所有先前的操作应该回滚。



这里有什么基本的想法?

@Transactional

 控制器操作 public MyController {
@Transactional
def save(){
myService.save(params)
myOtherService.save(params)
rendersuccess
}

...

}


In my controller I have a action which updates 2 domain class.

I want it to make in such a way that if the second updates fails first update should roll back, basically if there is an error all the previous actions should roll back.

What's the basic idea here?

解决方案

If you don't want to move your logic to a Service (possibly because you may be calling multiple services to execute both of those updates), annotate your controller action with @Transactional.

public MyController {
 @Transactional
 def save(){
   myService.save(params)
   myOtherService.save(params)
   render "success"
 }

 ...

}

这篇关于制造控制器交易控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆