Spring 注解 事务

来源:互联网 发布:网络直播怎么下载 编辑:程序博客网 时间:2024/06/05 18:59
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);    }
0 0
原创粉丝点击