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; } }