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

}
相关推荐
q***69775 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
tanxiaomi11 小时前
Spring、Spring MVC 和 Spring Boot ,mybatis 相关面试题
java·开发语言·mybatis
q***965815 小时前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
p***930317 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
chxii17 小时前
在 MyBatis 中开启 SQL 日志
java·数据库·mybatis
222you1 天前
MyBatis-Plus当中BaseMapper接口的增删查改操作
java·开发语言·mybatis
k***85841 天前
SpringBoot(整合MyBatis + MyBatis-Plus + MyBatisX插件使用)
spring boot·tomcat·mybatis
转转技术团队1 天前
MyBatis-Plus踩坑血泪史:那些年我们踩过的坑!
java·面试·mybatis
chxii1 天前
mybatis-spring 浅析
java·spring·mybatis
程序员小胖2 天前
困扰我一整天的MyBatis"Invalid bound statement"问题,原来是因为这个不起眼的注解冲突!
面试·mybatis