分页查询(待更新)

分页查询(待更新),第1张

分页查询 pagehelper

(官网地址:https://pagehelper.github.io/)
特点:1)支持多种数据库 2)支持多种分页方式 3)

pagehelper的使用 1)引入依赖(引入分页插件)

1、springboot集成

<dependency>
    <groupId>com.github.pagehelpergroupId>
    <artifactId>pagehelper-spring-boot-starterartifactId>
    <version>1.3.0version>
dependency>

2、spring集成

<dependency>
    <groupId>com.github.pagehelpergroupId>
    <artifactId>pagehelperartifactId>
    <version>最新版本version>
dependency>

这里引入的是整合的springboot的jar包

2)配置分页插件(三种方式)

(也称为配置拦截器插件)
参数配置(参考官网):https://pagehelper.github.io/docs/howtouse/

  1. spring-boot项目在application.yml中进行配置(推荐)
 		pagehelper:
 			helper-dialect: mysql  //指定数据库语言,不指定会自动检测
  1. 在mybatis-config-xml中进行配置
 
<plugins>
    
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
        
        <property name="param1" value="value1"/>
	plugin>
plugins>

interceptor=”PageHelper类所在包名“
如何获取包名所在的位置?
3. 在Spring的配置文件中进行配置

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  
  <property name="plugins">
    <array>
      <bean class="com.github.pagehelper.PageInterceptor">
        <property name="properties">
          
          <value>
            params=value1
          value>
        property>
      bean>
    array>
  property>
bean>

参数配置:见官网:https://pagehelper.github.io/docs/howtouse/

3)使用 (分页插件的调用方式)

1)PageHelper.startPage( )方法的使用
(步骤:1、查询几页(设置pageNUm和PageSize) 2、查询数据库(书写查询语句))
好处:不需要在查询语句中设置分页条件

PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectIf(1);

list是Page类,并且Page类是继承ArrayList

PageHelper.startPage( ),这个分页方法只对于它的下面的语句进行分页,中间不可以出现其他语句,否则可能报错

其他使用方式遇到更新

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/729100.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存