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

}
相关推荐
shsh2004 小时前
mybatis plus打印sql日志
数据库·sql·mybatis
草履虫建模16 小时前
Java面试应对思路和题库
java·jvm·spring boot·分布式·spring cloud·面试·mybatis
Hx_Ma1617 小时前
Springboot整合mybatis配置文件
spring boot·后端·mybatis
手握风云-17 小时前
JavaEE 进阶第十九期:MyBatis-Plus,让 CRUD 飞起来
java·java-ee·mybatis
那我掉的头发算什么19 小时前
【图书管理系统】基于Spring全家桶的图书管理系统(上)
java·服务器·数据库·spring boot·后端·spring·mybatis
❀͜͡傀儡师1 天前
基于mybatis-plus进行加解密 Spring Boot Starter
spring boot·oracle·mybatis
csdn2015_1 天前
mybatisplus自动生成id
java·mybatis
xEurCjvwu2 天前
台达PLC与C#串口通信实现实时同步读写监控功能:配置地址以XML文件为基础动态生成控件
mybatis
LSL666_2 天前
6 持久化
redis·mybatis·持久化·aof·rdb
哈库纳玛塔塔2 天前
AI 时代,使用 dbVisitor 读写向量化数据
数据库·人工智能·mybatis