分页插件Mybatis

xml 复制代码
    <plugins>
        <!-- com.github.pagehelper为PageHelper类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <!-- 配置方言:告诉分页插件使用底层数据库是什么-->
            <property name="helperDialect" value="mysql"/>
            <!-- 配置合理化参数:上一页和最后一页 不做加减操作,始终咨询第一页和最后一页-->
            <property name="reasonable" value="true"/>
        </plugin>
    </plugins>



 <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.2.0</version>
        </dependency>
java 复制代码
@Test
public void test(){
    SqlSession sqlSession = MyBatisUtils.getSqlSession();
    BookMapper mapper = sqlSession.getMapper(BookMapper.class);
    //分页
    PageHelper.startPage(2,5);
    List<Book> byPage = mapper.findByPage();
    //分页对象,里面有各种上一页,下一页,总页数,什么的数据
    PageInfo<Book> pageInfo = new PageInfo<>(byPage);
    for (Book book : byPage) {
        System.out.println(book);
    }

    System.out.println("---------------");
    System.out.println(pageInfo);
    System.out.println(pageInfo.getList());

}
相关推荐
zc.z4 小时前
高并发在线考试系统稳定性保障方案
mybatis·高并发
gAlAxy...6 小时前
MyBatis-Plus 核心 CRUD 操作全解析:BaseMapper 与通用 Service 实战
java·开发语言·mybatis
好好研究6 小时前
MyBatis - Plus(二)常见注解 + 常见配置
数据库·spring boot·mybatis·mybatis plus
树码小子8 小时前
Mybatis(8)#{}和${}的区别,排序,模糊查询
mybatis
在坚持一下我可没意见13 小时前
ideaPool论坛系统测试报告
java·spring boot·功能测试·selenium·jmeter·mybatis·压力测试
树码小子14 小时前
Mybatis(7)其他查询操作(多表查询)
spring boot·mybatis
NGC_661117 小时前
Mybatis处理流程
数据库·oracle·mybatis
SelectDB技术团队18 小时前
Apache Doris 4.0.3 版本正式发布
apache·mybatis
青云计划1 天前
知光项目知文发布模块
java·后端·spring·mybatis
Hx_Ma161 天前
Springboot整合mybatis注解版
java·spring boot·mybatis