Spring中@Transactional(rollbackFor = Throwable.class)的做用

場景

老大修改個人代碼規範時加了它數據庫

做用描述

Spring中的@Transactional(rollbackFor = Exception.class)事務處理,當你的方法中拋出異常時,它會將事務回滾到進入此方法前的狀態,數據庫中的數據將不會改變。app

舉個栗子

[@Service](https://my.oschina.net/service)
public class HexCaseConfServiceImpl implements HexCaseConfService {

[@Resource](https://my.oschina.net/u/929718)
private HexPmsCaseConfMapper hexPmsCaseConfMapper;

@Transactional(rollbackFor = Throwable.class)
[@Override](https://my.oschina.net/u/1162528)
public MessageResult removeHexPmsCaseConf(String[] noticeIds) throws Exception { 
	...
	}
}
相關文章
相關標籤/搜索