spring開啓事務在service層

spring開啓事務在service層

開啓事務在Service層,當Service層中某個事務方法中存在多個操作,例:


@Service("personService")
public class PersonServiceImpl implements PersonService {
@Resource
private PersonDao personDao;

@Override
public void testPerson(Person person,Account account)  {

this.personDao.insertPerson(person);

                this.personDao.updateAccount(account);

                int i=1/0;

}

}

當代碼執行到 int=1/0時,拋出異常,此時insertPerson,updateAccount都將回滾。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章