maven项目创7 配置分页插件

页面编写顺序   dao层mybatis配置——》service层的接口及实现类——》controller(web下)

分页插件作用于dao层,与之相关的是mybatis的配置

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

<configuration>
    <!-- 配置分页插件 -->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->        
            <property name="dialect" value="mysql"/>
        </plugin>
    </plugins>
</configuration>

然后在执行sql语句前加上

//分页处理

PageHelper.startPage(1, 10);
List<TbItem> list = mapper.selectByExample(example);//执行sql语句,返回列表

  //分页信息
  PageInfo<TbItem> pageInfo=new PageInfo<>(list);
  long total = pageInfo.getTotal();
  System.out.println("共有商品:"+ total);

猜你喜欢

转载自www.cnblogs.com/dianzan/p/11106649.html