杰表技术论坛 's Archiver

admin 发表于 2012-5-8 17:44

使用事务模板,进行事务管理

[font=monospace]
[/font]
[size=12px]TransactionDefinition transactionDefinition = new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED);[/size]
[size=12px]new TransactionTemplate(transactionManager, transactionDefinition).execute(new TransactionCallback()[/size]
[size=12px]{[/size]
[size=12px]    @Override[/size]
[size=12px]    public Object doInTransaction(TransactionStatus status)[/size]
[size=12px]    {[/size]
[size=12px]        // ... execute transactional code ...[/size]

[size=12px]        return null;[/size]
[size=12px]    }[/size]
[size=12px]});[/size]
[size=12px]
[/size]
[size=12px][font=monospace]TransactionDefinition.PROPAGATION_REQUIRED: 已经在事务中,则参与,否则另起一个事务[/font][/size]
[size=12px][font=monospace]transactionManager:[/font][font=monospace]org.springframework.transaction.PlatformTransactionManager 可以从容器中,得到[/font][/size]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.