乐趣区

关于mybatis-plus:Mybatisplus分页

增加依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.0</version>
        </dependency>

在启动类编辑

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
        return interceptor;
    }

Mapper 层编写

IPage<User> getList(Page<Object> page);

xml 文件编写 SQL

    <select id="getList" resultMap="getUserDate">
        select * from user
<!--         select * from user 最初不能增加; 号 -->
    </select>

Test 测试

    @Test
    void Test01(){Page<Object> page = new Page<>(0, 2);
        List<User> records = userMapper.getList(page).getRecords();
        records.forEach(item->System.out.println(item));
    }
退出移动版