美文网首页
pageHelper5 结合mybatis实现分页

pageHelper5 结合mybatis实现分页

作者: 众生皆苦_3547 | 来源:发表于2018-11-15 11:45 被阅读0次

    1. 引入pageHelper依赖

              <dependency>
                    <groupId>com.github.pagehelper</groupId>
                    <artifactId>pagehelper</artifactId>
                    <version>5.1.8</version>
                </dependency>
    

    2. mybatis配置sqlMapConfig.xml文件中配置添加pageHelper的plugin

    <configuration>
        <plugins>
            <plugin interceptor="com.github.pagehelper.PageInterceptor">
            </plugin>
        </plugins>
    </configuration>
    

    pageHelper 5以下的版本可能需要配置以下类(5中的Interceptor接口实现类在com.github.pagehelper.PageInterceptor中,之前版本是com.github.pagehelper.PageHelper就实现了Interceptor)

    <configuration>
        <plugins>
            <plugin interceptor="com.github.pagehelper.PageInterceptor">
                <property name="dialect" value="mysql"/>
            </plugin>
        </plugins>
    </configuration>
    

    3. 代码实现分页功能

    //获取第1页,10条内容,紧跟的第一个查询才会被分页
    PageHelper.startPage(1, 10);
    List<Country> list = countryMapper.selectAll();
    //用PageInfo对结果进行包装
    PageInfo page = new PageInfo(list);
    

    相关文章

      网友评论

          本文标题:pageHelper5 结合mybatis实现分页

          本文链接:https://www.haomeiwen.com/subject/bizefqtx.html