@Transactional
    在处理dao层或service层的事务操作时,譬如删除失败时的回滚操作。使用@Transactional 作为注解,但是需要在配置文件激活。

    1. <!-- 开启注解方式声明事务 -->
    2. <tx:annotation-driven transaction-manager="transactionManager" />
    1. @Service
    2. public class CompanyServiceImpl implements CompanyService {
    3. @Autowired
    4. private CompanyDAO companyDAO;
    5. @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    6. public int deleteByName(String name) {
    7. int result = companyDAO.deleteByName(name);
    8. return result;
    9. }
    10. ...
    11. }

    image.png
    image.png