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都將回滾。