在使用spring的时候通常我们可以通过抛出异常的方式完成回滚,当然是runtime的异常,但是在一些复杂业务逻辑1中,往往我们需要service返回的不只是异常信息,很可能是异常的code,甚至一些其他的信息。
这个时候我们就不能抛出异常,那么这个时候可以通过一下方法完成数据库的回滚:
TransactionInterceptor.CurrentTransactionStatus.RollbackOnly = true
或者
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
这个应该是不同版本的使用方式。
参考地址:
http://forum.springframework.net/archive/index.php/t-4264.html
这个时候我们就不能抛出异常,那么这个时候可以通过一下方法完成数据库的回滚:
TransactionInterceptor.CurrentTransactionStatus.RollbackOnly = true
或者
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
这个应该是不同版本的使用方式。
参考地址:
http://forum.springframework.net/archive/index.php/t-4264.html
本文介绍在复杂的业务逻辑中,如何在不抛出异常的情况下完成Spring事务的回滚。通过设置TransactionInterceptor.CurrentTransactionStatus.RollbackOnly为true来实现。适用于需要返回异常代码和其他信息的场景。
971

被折叠的 条评论
为什么被折叠?



