Mybatis增删改的事务提交

问题展示

手动提交事务:sqlSession.commit();

自动提交:sqlSessionFactory.openSession(true);


我们的mysql中,涉及增删改的语句都要提交事务,不然不起作用,下面我们就讲讲mybaits中的事务提交

问题展示

我们的插入语句的单元测试没有提交事务,导致数据没有插到数据库

手动提交事务:sqlSession.commit();

手动提交需要每个需要提交事务的地方,都要手动写一遍

自动提交:sqlSessionFactory.openSession(true);

先看源码

原来我们的

现在修改为自动提交事务

事务提交成功 

猜你喜欢

转载自blog.csdn.net/lgl782519197/article/details/109223113
今日推荐