美文网首页
SpringBoot中使用PageHelper

SpringBoot中使用PageHelper

作者: ghbhaha | 来源:发表于2018-09-16 22:32 被阅读0次

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

    1.添加jar包

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper</artifactId>
        <version>5.1.2</version>
    </dependency>
    

    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

          本文链接:https://www.haomeiwen.com/subject/idlqnftx.html