SSM项目使用PageHelper插件实现分页

1.在pom.xml中添加

        <!--pagehelper分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>
        <dependency>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
            <version>1.2</version>
        </dependency>        

2.maybatis配置文件中添加(我的配置文件是在applicationCoontent.xml)

<!-- 分页插件 -->
       <property name="plugins">
           <array>
           <!-- com.github.pagehelper为PageHelper类所在包名 -->
               <bean class="com.github.pagehelper.PageHelper">
                   <property name="properties">
                       <value>
                           dialect=mysql
                       </value>
                   </property>
               </bean>
           </array>
       </property> 

添加的位置如下:

 3.在service的实现类中分页:

    PageHelper.startPage(page, limit);
        List<Deformity> list = deformityDao.selectByMap(chinaName);
        // 分页查询
        PageInfo<Deformity> pageInfo = new PageInfo<Deformity>(list);
        return new ResultData(true, "查询成功", pageInfo.getList(), pageInfo.getTotal());

标红的代码是主要分页的代码。

就是这么简单,你学废了吗?感觉有用的话,给笔者点个赞吧 !
原文地址:https://www.cnblogs.com/zys2019/p/14481112.html