用mybatis中的


<insert >
  insert INTO MyTable(createModel) VALUES(#{createModel})
</insert>


在测试类中写了这个


int count = sqlSession.getMapper(ComputerMapper.class).add(com1);


结果是count=1


但是在数据库中却没有找到插入的数据,找了一下,原来是写


factory.openSession(false);


的时候,设置了没有自动提交


在返回count后面加上


sqlSession.commit();


就可以了,提交事务  。


如果上面的factory.openSession(false)这个参数改为true,即factory.openSession(true);


那么当返回1的时候,数据就添加到数据库中了,自动提交 原文地址:https://blog.csdn.net/MyMBS/article/details/79827832

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
猜你喜欢
  • 2021-09-01
  • 2021-05-27
  • 2021-08-14
  • 2021-04-16
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案