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时回滚。

相关文章:

  • 2021-09-14
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-02-28
相关资源
相似解决方案