SpringBoot中使用PageHelper

由于网上关于SpringBoot中使用PageHelper过于陈旧,不适用于新版,所以研究记录下

1.添加jar包


    com.github.pagehelper
    pagehelper
    5.1.2

2.添加配置PageHelperConf

import com.github.pagehelper.PageInterceptor;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;

/**
 * 分页配置
 * @author guhaibo
 * @date 2018/9/16
 */
@Configuration
public class PageHelperConf {
    public PageHelperConf(SqlSessionFactory mysqlSessionFactory){
        Properties properties = new Properties();
        properties.setProperty("helperDialect", "mysql");
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "true");
        Interceptor interceptor = new PageInterceptor();
        interceptor.setProperties(properties);
        mysqlSessionFactory.getConfiguration().addInterceptor(interceptor);
    }
}

参考文章:https://blog.csdn.net/qq_33934809/article/details/79001736

你可能感兴趣的:(SpringBoot中使用PageHelper)