Spring 注解 事务

1、Spring项目中事务手动回滚:
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

或者抛出异常:
	@Transactional(rollbackFor = { Exception.class, RuntimeException.class })
	public HousingFundDto slogin(){
		try {
...
throw new BusinessException("无法查询基本信息");
...}catch (BusinessException e) {
			throw new BusinessException(e.getErrorDesc());
		} 

}
引用:
http://blog.csdn.net/yh88356656/article/details/52174817

2、
 /**
     * 更新
     */
    @Transactional(rollbackFor = { Exception.class, RuntimeException.class })
    public void update(Entity entity) {
        targetDao.update(entity);
    }

    /**
     * 新增
     */
    @Transactional(rollbackFor = { Exception.class, RuntimeException.class })
    public void insert(Entity entity) {
        targetDao.insert(entity);
    }


3、引用参考
--Spring事务的传播特性和隔离级别
http://www.iteye.com/topic/1147215

猜你喜欢

转载自franciswmf.iteye.com/blog/2344375