PageHelper不生效的原因

PageHelper是一个比较简单的分页插件,但是好些人在用的时候却无法生效了。

遇到这种情况不要方,首先先看看自己的配置,我这里用的是注解配置

import com.github.pagehelper.PageHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * mybatis分页插件配置
 */
@Configuration
public class MybatisConfig {
    @Bean
    public PageHelper pageHelper(){
        PageHelper pageHelper=new PageHelper();
        Properties properties=new Properties();
        //把这个设置为true,会带RowBounds第一个参数offset当成PageNum使用
        properties.setProperty("offsetAsPageNum","true");
        //设置为true时,使用RowBounds分页会进行count查询
        properties.setProperty("rowBoundsWithCount","true");
        properties.setProperty("reasonable","true");
        pageHelper.setProperties(properties);
        return pageHelper;
    }
}

如果在使用注解配置的时候,需要加一个@Configuration 表示这个类是一个配置类,相当于Spring配置文件中的<beans>,再加上@Bean 进行Bean注入

然后再看看你的分页查询是不是在你的查询语句之前 

        PageHelper.startPage(page,size);
        List<Video> list=videoService.findAll();
        PageInfo<Video> pageInfo=new PageInfo<Video>(list);
        return pageInfo;

我这次遇到的错也是把前面的都改了,然后发现还是没用,查出来的还是全部数据。然后选择刷一下缓存

发现可以查询成功了。

JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@716f8341] will not be managed by Spring
==>  Preparing: SELECT count(0) FROM video 
==> Parameters: 
<==    Columns: count(0)
<==        Row: 10
<==      Total: 1
==>  Preparing: select * from video limit ?,? 
==> Parameters: 0(Integer), 10(Integer)

猜你喜欢

转载自blog.csdn.net/OrangeRawNorthland/article/details/86480431