Mybatis-plus的两种分页插件的配置方式
Posted leeego-123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis-plus的两种分页插件的配置方式相关的知识,希望对你有一定的参考价值。
第一种:
package com.paic.ocss.gateway.admin.config; import com.baomidou.mybatisplus.plugins.PaginationInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import com.baomidou.mybatisplus.entity.GlobalConfiguration; /** * mybatis的配置类 * * @author zhangkai940 * @date 2018-11-22 */ @Configuration @MapperScan({"com.paic.ocss.gateway.dao.mapper","com.paic.ocss.gateway.admin.mapper"}) @Import(value = { com.paic.ocss.monitor.cat.mybatis.SpringCloudCatMybatisConfig.class }) public class MybatisConfig { @Bean public GlobalConfiguration globalConfiguration() { GlobalConfiguration global = new GlobalConfiguration(); global.setDbType("mysql"); return global; } @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor page = new PaginationInterceptor(); page.setDialectType("mysql"); return page; } }
第二种:
package com.paic.ocss.gateway.dao.config; import com.baomidou.mybatisplus.entity.GlobalConfiguration; import com.github.pagehelper.PageHelper; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import java.util.Properties; @Configuration @MapperScan("com.paic.ocss.gateway.dao.mapper*") @Import(value = { com.paic.ocss.monitor.cat.mybatis.SpringCloudCatMybatisConfig.class }) public class MybatisConfig { @Bean public GlobalConfiguration globalConfiguration() { GlobalConfiguration global = new GlobalConfiguration(); global.setDbType("mysql"); return global; } /** * 配置mybatis的分页插件pageHelper * @return */ @Bean public PageHelper pageHelper(){ PageHelper pageHelper = new PageHelper(); Properties properties = new Properties(); properties.setProperty("offsetAsPageNum","true"); properties.setProperty("rowBoundsWithCount","true"); properties.setProperty("reasonable","true"); //配置mysql数据库的方言 properties.setProperty("dialect","mysql"); pageHelper.setProperties(properties); return pageHelper; } }
以上是关于Mybatis-plus的两种分页插件的配置方式的主要内容,如果未能解决你的问题,请参考以下文章
mybatis的两种分页方式:RowBounds和PageHelper