use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project platform by elveahuang.
the class CustomMyBatisAutoConfiguration method mybatisPlusInterceptor.
/**
* MyBatis自定义配置
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project jeebiz-boot by Jeebiz.
the class MybatisPlusConfiguration method paginationInterceptor.
/**
* mybatis-plus分页插件<br>
* 文档:http://mp.baomidou.com<br>
*/
@Bean
public PaginationInnerInterceptor paginationInterceptor() {
PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
paginationInterceptor.setOverflow(false);
return paginationInterceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project coding-more by itwanger.
the class MyBatisConfig method mybatisPlusInterceptor.
// 最新版
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project lamp-util by zuihou.
the class BaseMybatisConfiguration method mybatisPlusInterceptor.
/**
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
* <p>
* 注意:
* 如果内部插件都是使用,需要注意顺序关系,建议使用如下顺序
* 多租户插件,动态表名插件
* 分页插件,乐观锁插件
* sql性能规范插件,防止全表更新与删除插件
* 总结: 对sql进行单次改造的优先放入,不对sql进行改造的最后放入
* <p>
* 参考:
* https://mybatis.plus/guide/interceptor.html#%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F-%E4%BB%A5%E5%88%86%E9%A1%B5%E6%8F%92%E4%BB%B6%E4%B8%BE%E4%BE%8B
*/
@Bean
@Order(5)
@ConditionalOnMissingBean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
log.info("检测到 lamp.database.multiTenantType={},已启用 {} 模式", databaseProperties.getMultiTenantType().name(), databaseProperties.getMultiTenantType().getDescribe());
if (StrUtil.equalsAny(databaseProperties.getMultiTenantType().name(), MultiTenantType.SCHEMA.name(), MultiTenantType.SCHEMA_COLUMN.name())) {
// SCHEMA 动态表名插件
SchemaInterceptor schemaInterceptor = new SchemaInterceptor(databaseProperties.getTenantDatabasePrefix());
interceptor.addInnerInterceptor(schemaInterceptor);
}
if (StrUtil.equalsAny(databaseProperties.getMultiTenantType().name(), MultiTenantType.COLUMN.name(), MultiTenantType.SCHEMA_COLUMN.name(), MultiTenantType.DATASOURCE_COLUMN.name())) {
// COLUMN 模式 多租户插件
TenantLineInnerInterceptor tli = new TenantLineInnerInterceptor();
tli.setTenantLineHandler(new TenantLineHandler() {
@Override
public String getTenantIdColumn() {
return databaseProperties.getTenantIdColumn();
}
@Override
public boolean ignoreTable(String tableName) {
return databaseProperties.getIgnoreTables() != null && databaseProperties.getIgnoreTables().contains(tableName);
}
@Override
public Expression getTenantId() {
return MultiTenantType.COLUMN.eq(databaseProperties.getMultiTenantType()) ? new StringValue(ContextUtil.getTenant()) : new StringValue(ContextUtil.getSubTenant());
}
});
interceptor.addInnerInterceptor(tli);
}
List<InnerInterceptor> beforeInnerInterceptor = getPaginationBeforeInnerInterceptor();
if (!beforeInnerInterceptor.isEmpty()) {
beforeInnerInterceptor.forEach(interceptor::addInnerInterceptor);
}
// 分页插件
PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
// 单页分页条数限制
paginationInterceptor.setMaxLimit(databaseProperties.getMaxLimit());
// 数据库类型
paginationInterceptor.setDbType(databaseProperties.getDbType());
// 溢出总页数后是否进行处理
paginationInterceptor.setOverflow(databaseProperties.getOverflow());
// 生成 countSql 优化掉 join 现在只支持 left join
paginationInterceptor.setOptimizeJoin(databaseProperties.getOptimizeJoin());
interceptor.addInnerInterceptor(paginationInterceptor);
List<InnerInterceptor> afterInnerInterceptor = getPaginationAfterInnerInterceptor();
if (!afterInnerInterceptor.isEmpty()) {
afterInnerInterceptor.forEach(interceptor::addInnerInterceptor);
}
// 防止全表更新与删除插件
if (databaseProperties.getIsBlockAttack()) {
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
}
// sql性能规范插件
if (databaseProperties.getIsIllegalSql()) {
interceptor.addInnerInterceptor(new IllegalSQLInnerInterceptor());
}
return interceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project mybatis-plus-samples by baomidou.
the class MybatisPlusConfig method sqlSessionFactory.
@Bean("mybatisSqlSession")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
/* 数据源 */
sqlSessionFactory.setDataSource(dataSource);
/* 枚举扫描 */
sqlSessionFactory.setTypeEnumsPackage("com.baomidou.mybatisplus.samples.mysql.enums");
/* xml扫描 */
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*.xml"));
/* 扫描 typeHandler */
// sqlSessionFactory.setTypeHandlersPackage("com.baomidou.mybatisplus.samples.mysql.type");
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setJdbcTypeForNull(JdbcType.NULL);
/* 驼峰转下划线 */
configuration.setMapUnderscoreToCamelCase(true);
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
/* map 下划线转驼峰 */
configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
sqlSessionFactory.setConfiguration(configuration);
/* 自动填充插件 */
globalConfig.setMetaObjectHandler(new MysqlMetaObjectHandler());
sqlSessionFactory.setGlobalConfig(globalConfig);
return sqlSessionFactory.getObject();
}
Aggregations