• 用mybatis中的insert方法插入数据,返回值为1,但数据库却没有数据


    用mybatis中的


    <insert id="add" parameterType="cn.entity.Computer">
      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
  • 相关阅读:
    ARC 117 D
    Maven依赖踩坑记录
    MobaXterm连接本地CentOS7
    Git在IDEA下的常用操作
    mq消息中间件
    nginx的作用
    Git的使用
    docker
    redis
    导出excel
  • 原文地址:https://www.cnblogs.com/jpfss/p/11630291.html
Copyright © 2020-2023  润新知