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

}
相关推荐
小坏讲微服务20 小时前
SpringBoot4.0整合Spring Security+MyBatis Plus完整权限框架实现
java·spring·mybatis·spring security·mybatis plus·springboot4.0
静小谢1 天前
sql笔记
spring boot·笔记·sql·mybatis
桔筐1 天前
MyBatis-Plus Service/ServiceImpl/IService 核心关系
mybatis
m0_739030001 天前
mabatis-plus 和mabatis 的区别
java·数据库·mybatis
步菲2 天前
【Java泛型擦除】一次 MyBatis 返回值不一致引发的线上故障复盘
mybatis
武子康2 天前
Java-01 深入浅出 MyBatis 入门与核心原理:半自动 ORM 框架详解
java·后端·mybatis
环流_3 天前
Redis:epoll和IO多路复用
java·redis·mybatis
欢璃3 天前
表白墙案例
java·开发语言·jvm·spring boot·spring·maven·mybatis
贫民窟的勇敢爷们3 天前
SpringBoot整合MyBatis-Plus极致实战,高效实现数据库CRUD与分页条件查询
数据库·spring boot·mybatis
暗暗别做白日梦3 天前
MyBatis-Plus 分页查询@Param 注解
mybatis