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();
        }

    【运行结果】

  • 相关阅读:
    Netty入门(三)之web服务器
    Math对象
    DOM
    BOM
    字符串
    数组
    ajax
    如何安装vue脚手架
    git提交拉取远程仓库
    第九届蓝桥杯,赛后感!!含泪写完。
  • 原文地址:https://www.cnblogs.com/HigginCui/p/5699778.html
Copyright © 2011-2022 走看看