spring boot jpa 事務管理


spring boot 對jpa的支持極為方便,基本上不需要作太多配置,只需要加上注解就能支持事務:

@Controller
@Transactional(rollbackOn = Exception.class)
public class TestController {
    @Autowired
    TestRepository testRepository;

    @RequestMapping(path = "/test")
    public void getAdminInfo(String currentAccount) throws  Exception
    {
        Test account = testRepository.save(new Test().setName("abc"));
        System.out.println(account);
    }
}

@Transactional(rollbackOn = Exception.class) 指在遇到Exception時就會回滾,而如果不標注rollbackOn,只會在拋RuntimeException時回滾。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM