zoukankan      html  css  js  c++  java
  • Mybatis批处理

            <!--批量插入-->
            <select id="batchInsert" parameterType="java.util.List">
                insert into t_goods(title,sub_title,original_cost,current_price,discount,is_free_delivery,category_id)
                values
                <foreach collection="list" item="item" index="index" separator=",">
                    (#{item.title},#{item.subTitle},#{item.originalCost},#{item.currentPrice},#{item.discount},
                    #{item.isFreeDelivery},#{item.categoryId})
                </foreach>
            </select>
        public void TestBatchInsert() throws Exception {
            SqlSession sqlSession = null;
            try {
                //获取sql对象
                sqlSession = MybatisUtils.openSession();
                //记录开始时间
                Long st = new Date().getTime();
                List<GoodsEntity> list = new ArrayList();
                for (int i = 0; i <30000 ; i++) {
                    GoodsEntity goodsEntity = new GoodsEntity();
                    goodsEntity.setTitle("测试商品");
                    goodsEntity.setSubTitle("测试商品子标题");
                    goodsEntity.setOriginalCost(1000f);
                    goodsEntity.setCurrentPrice(800f);
                    goodsEntity.setDiscount(0.8f);
                    goodsEntity.setIsFreeDelivery(1);
                    goodsEntity.setCategoryId(43);
                    list.add(goodsEntity);
                }
                //执行sql
                sqlSession.insert("goods.batchInsert",list);
                //提交数据
                sqlSession.commit();
                //记录结束时间
                Long et = new Date().getTime();
                System.out.println("总花费时间:"+(et-st)+"--");
                //查看连接状态
                Connection conn = MybatisUtils.getConnection(sqlSession);
    
            }catch (Exception e){
                sqlSession.rollback();//数据回滚
                throw e;
            }finally {
                MybatisUtils.release(sqlSession);
            }
        }
  • 相关阅读:
    web页面中四种常见必测控件
    python03
    python基础2
    python基础
    如何定位测试用例的作用?
    需求测试的注意事项有哪些?
    性能测试的流程?
    简述bug的生命周期?
    Python字符串
    Python基础语法
  • 原文地址:https://www.cnblogs.com/wuheng-123/p/13840594.html
Copyright © 2011-2022 走看看