SpringBoot mybatis 自定义分页插件 注解版

1.要使用4.1版本以上的,否则可能不生效

<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>4.1.0</version>
    </dependency>
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
    /**
     * 注册分页插件
     * @return
     */
    /**
     * 注册MyBatis分页插件PageHelper
     */
    private static String dialect = "dialect";
    private static String offsetAsPageNum = "offsetAsPageNum";
    private static String rowBoundsWithCount = "rowBoundsWithCount";
    private static String reasonable = "reasonable";
    private static String database = "mysql";
    private static String t = "true";

    @Bean
    public PageHelper pageHelper() {
        PageHelper pageHelper = new PageHelper();
        Properties p = new Properties();
        p.setProperty(dialect, database);
        p.setProperty(offsetAsPageNum, t);
        p.setProperty(rowBoundsWithCount, t);
        p.setProperty(reasonable, t);
        pageHelper.setProperties(p);
        return pageHelper;
    }
posted @ 2019-11-18 11:29  smileLS66  阅读(87)  评论(0编辑  收藏  举报