Mybatis-plus分页

LLL333

添加依赖

        <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));
    }
阅读 272
12 声望
3 粉丝
0 条评论
你知道吗?

12 声望
3 粉丝
文章目录
宣传栏