批量操作与分页

Batch 批量操作

session = build.openSession(ExecutorType.BATCH, false);

    /*
    方式1 普通for循环插入
    方式2
    sql使用foreach拼接sql :有 SQL 长度限制,定好 List大小
    方式3
    ExecutorType.BATCH
    批量插入
    */
    @Test
    public void test11() {
        long start = System.currentTimeMillis();
        TestMapper mapper = session.getMapper(TestMapper.class);
        for (int i = 0; i < 1000; i++) {
            mapper.insertExample(new mapper.Test(null, new Date()));
            session.commit();
        }
        System.out.println(System.currentTimeMillis() - start);
    }
    

分页

物理分页:分页面插件 https://github.com/pagehelper/Mybatis-PageHelper

    <plugin interceptor="com.github.pagehelper.PageInterceptor">
        <!--<property name="dialect" value="mysql"/>-->
        <!--<property name="reasonable" value="true" />-->
    </plugin>
    //分页
    @Test
    public void test4() {
        TestMapper mapper = session.getMapper(TestMapper.class);
        PageHelper.startPage(1, 5);
        List<mapper.Test> list = mapper.selectByReg2();
        PageInfo<mapper.Test> pageInfo = new PageInfo<mapper.Test>(list);
        System.out.println("pageInfo = " + pageInfo.getSize());
    }
posted @ 2019-02-20 10:50  fly_bk  阅读(430)  评论(0编辑  收藏  举报