spring boot controller设置 @Transactional 不回滚的解决办法
spring boot controller设置 @Transactional 不回滚的解决办法 在spring boot 中,使用事务非常简单,直接在方法上面加入@Transactional就可以实现,以下是我的做法 @GetMapping("delete") @ResponseBody @Transactional publicvoiddelete(@RequestParam("id")intid){ try{//deletecountry this.repository.delete(id); if(id==1){ throwException("测试事务"); } //deletecity this.repository.deleteByCountryId(id); }catch(Exceptione){ logger.error("deletefalse:"+e.getMessage()); returnnewMessageBean(101,"deletefalse"); } } 发现事务不回滚,即this.repository.delete(id); 成功把数据删除了。 原...