分页插件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());

}
相关推荐
设计师小聂!16 小时前
尚庭公寓----------分页查询
java·开发语言·spring·maven·mybatis
秋秋棠1 天前
MyBatis延迟加载(Lazy Loading)之“关联查询”深度解析与实践
java·mybatis
秋秋棠1 天前
MyBatis级联查询深度解析:一对多关联实战指南
jvm·tomcat·mybatis
hello 早上好2 天前
MyBatis 动态 SQL、#{}与 ${}区别、与 Hibernate区别、延迟加载、优势、XML映射关系
sql·mybatis·hibernate
我命由我123452 天前
Spring Boot - Spring Boot 集成 MyBatis 分页实现 手写 SQL 分页
java·spring boot·后端·sql·spring·java-ee·mybatis
艺杯羹2 天前
MyBatis 之分页四式传参与聚合、主键操作全解
java·开发语言·maven·mybatis
设计师小聂!2 天前
尚庭公寓-----day1 业务功能实现
java·ide·spring·maven·mybatis
郑州吴彦祖7722 天前
Mybatis的SQL编写—XML方式
java·sql·spring·mybatis
Raners_2 天前
【Java代码审计(2)】MyBatis XML 注入审计
xml·java·安全·网络安全·mybatis
别来无恙1493 天前
Spring Boot + MyBatis 实现用户登录功能详解(基础)
spring boot·后端·mybatis