zoukankan      html  css  js  c++  java
  • 04_删除数据

    【user.xml】

    <!-- 删除用户 -->
         <delete id="deleteUserById" parameterType="java.lang.Integer">
             delete from user where id=#{id}
         </delete>

    【MyBatisTest.java】

    @Test
        public void testDeleteUser() throws IOException{
            //mybatis映射文件
            String resource="sqlMapConfig.xml";
            //得到mybatis映射文件
            InputStream inputStream=Resources.getResourceAsStream(resource);
            //创建会话,传递mybatis配置信息
            SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
            //通过工厂得到session
            SqlSession sqlSession=sqlSessionFactory.openSession();
            
            //传入id,删除用户
            sqlSession.delete("test.deleteUserById",2);
            
            //提交事务
            sqlSession.commit(); //这句必须要有,不然插不进去数据 
            //关闭会话
            sqlSession.close();
        }

    【运行结果】

  • 相关阅读:
    Animation(三)
    布局
    AutoCommpleteText
    PHP数组中常用函数
    Animation(四)
    转:JAVA内存映射文件
    Ubuntu安装jdk
    转:Java NIO 详解
    转:长连接与短连接
    Direct or Nondirect ByteBuffer
  • 原文地址:https://www.cnblogs.com/HigginCui/p/5699778.html
Copyright © 2011-2022 走看看