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

}
相关推荐
可乐ea1 小时前
【Spring Boot + MyBatis|第7篇】JWT 登录认证与拦截器实现
java·spring boot·后端·mybatis·状态模式
摇滚侠2 小时前
MyBatis 入门到项目实战 MyBatis 核心配置文件 15-19
java·tomcat·mybatis
摇滚侠5 小时前
MyBatis 入门到项目实战 IDEA 配置模板 20-22
java·intellij-idea·mybatis
独泪了无痕14 小时前
MyBatis魔法堂:结果集映射
后端·mybatis
就叫_这个吧20 小时前
IDEA Mybatis xml文件,实现sql语句联想,自动填入补充
xml·mysql·intellij-idea·mybatis
熠熠仔1 天前
Spring Boot 与 MyBatis-Plus 空间几何数据集成指南
spring boot·后端·mybatis
范什么特西1 天前
重点:mybatis注意细节
java·mysql·mybatis
接着奏乐接着舞1 天前
springboot mp mybatis plaus
windows·spring boot·mybatis
_Aaron___1 天前
MyBatis 动态排序别乱用 ${}:ORDER BY 的安全写法
java·spring·mybatis
存在的五月雨2 天前
MyBatis 中,#{} 和 ${}的区别
mybatis