mybatis 和 mybatis plus 分页的配置

package com.dmo.parkingview.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/*
 * @Author jt
 * @Description //MybatisPlus 分页插件
 * @Date 2020/7/13
 **/
@Configuration
public class MybatisPlusConfig {
//下面是mybatisplus 分页的配置
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
        // paginationInterceptor.setOverflow(false);
        // 设置最大单页限制数量,默认 500 条,-1 不受限制
        // paginationInterceptor.setLimit(500);
        // 开启 count 的 join 优化,只针对部分 left join
        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
        return paginationInterceptor;
    }
// 下面是mybatis 分页插件的配置
    @Bean
    public PageHelper pageHelper() {
        // 分页插件pageHelper
        PageHelper pageHelper = new PageHelper();
        Properties properties = new Properties();
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        //reasonable分页参数合理化,3.3.0以上版本可用,默认是false。
        // 启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页;
        // 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据。
        properties.setProperty("reasonable", "false");
        properties.setProperty("helperDialect", "mysql");
        pageHelper.setProperties(properties);
        return pageHelper;
    }


    @Configuration
    @AutoConfigureAfter(MybatisPlusConfig.class)
    public static class MyBatisMapper {

        @Bean
        public MapperHelper mapperHelper() {
            //配置通用mappers
            MapperHelper mapperHelper = new MapperHelper();
            Properties properties = new Properties();
            properties.setProperty("mappers", "tk.mybatis.mapper.common.Mapper");
            properties.setProperty("notEmpty", "false");
            properties.setProperty("IDENTITY", "MYSQL");
            mapperHelper.setProperties(properties);
            return mapperHelper;
        }

    }
}

 


版权声明:本文为qianhuan_原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。