public abstract class BaseMybatisConfiguration extends Object
拦截器执行一定是: WriteInterceptor > DataScopeInterceptor > PaginationInterceptor
| 限定符和类型 | 字段和说明 |
|---|---|
protected DatabaseProperties |
databaseProperties |
| 构造器和说明 |
|---|
BaseMybatisConfiguration(DatabaseProperties databaseProperties) |
| 限定符和类型 | 方法和说明 |
|---|---|
DisposableWorkerIdAssigner |
disposableWorkerIdAssigner(WorkerNodeDao workerNodeDao) |
UidGenerator |
getCacheUidGenerator(DisposableWorkerIdAssigner disposableWorkerIdAssigner) |
UidGenerator |
getDefaultUidGenerator(DisposableWorkerIdAssigner disposableWorkerIdAssigner) |
FullLikeTypeHandler |
getFullLikeTypeHandler()
Mybatis 自定义的类型处理器: 处理XML中 #{name,typeHandler=fullLike} 类型的参数
用于全模糊查询时使用
eg:
and name like #{name,typeHandler=fullLike}
|
UidGenerator |
getHuToolUidGenerator() |
LeftLikeTypeHandler |
getLeftLikeTypeHandler()
Mybatis 自定义的类型处理器: 处理XML中 #{name,typeHandler=leftLike} 类型的参数
用于左模糊查询时使用
eg:
and name like #{name,typeHandler=leftLike}
|
com.baomidou.mybatisplus.core.handlers.MetaObjectHandler |
getMyMetaObjectHandler()
Mybatis Plus 注入器
|
LampSqlInjector |
getMySqlInjector() |
protected List<com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor> |
getPaginationAfterInnerInterceptor()
分页拦截器之后的插件
|
protected List<com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor> |
getPaginationBeforeInnerInterceptor()
分页拦截器之前的插件
|
RightLikeTypeHandler |
getRightLikeTypeHandler()
Mybatis 自定义的类型处理器: 处理XML中 #{name,typeHandler=rightLike} 类型的参数
用于右模糊查询时使用
eg:
and name like #{name,typeHandler=rightLike}
|
WriteInterceptor |
getWriteInterceptor()
演示环境权限拦截器
|
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor |
mybatisPlusInterceptor()
新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
注意:
如果内部插件都是使用,需要注意顺序关系,建议使用如下顺序
多租户插件,动态表名插件
分页插件,乐观锁插件
sql性能规范插件,防止全表更新与删除插件
总结: 对sql进行单次改造的优先放入,不对sql进行改造的最后放入
参考:
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
|
protected final DatabaseProperties databaseProperties
public BaseMybatisConfiguration(DatabaseProperties databaseProperties)
@Bean
@Order(value=15)
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix="lamp.database",
name="isNotWrite",
havingValue="true")
public WriteInterceptor getWriteInterceptor()
@Bean @Order(value=5) @ConditionalOnMissingBean public com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor mybatisPlusInterceptor()
注意: 如果内部插件都是使用,需要注意顺序关系,建议使用如下顺序 多租户插件,动态表名插件 分页插件,乐观锁插件 sql性能规范插件,防止全表更新与删除插件 总结: 对sql进行单次改造的优先放入,不对sql进行改造的最后放入
参考: 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
protected List<com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor> getPaginationAfterInnerInterceptor()
protected List<com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor> getPaginationBeforeInnerInterceptor()
@Bean(value="myMetaObjectHandler") @ConditionalOnMissingBean public com.baomidou.mybatisplus.core.handlers.MetaObjectHandler getMyMetaObjectHandler()
@Bean
@ConditionalOnMissingBean
@ConditionalOnExpression(value="\'DEFAULT\'.equals(\'${lamp.database.id-type:DEFAULT}\') || \'CACHE\'.equals(\'${lamp.database.id-type:DEFAULT}\')")
public DisposableWorkerIdAssigner disposableWorkerIdAssigner(WorkerNodeDao workerNodeDao)
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix="lamp.database",
name="id-type",
havingValue="DEFAULT",
matchIfMissing=true)
public UidGenerator getDefaultUidGenerator(DisposableWorkerIdAssigner disposableWorkerIdAssigner)
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix="lamp.database",
name="id-type",
havingValue="CACHE")
public UidGenerator getCacheUidGenerator(DisposableWorkerIdAssigner disposableWorkerIdAssigner)
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix="lamp.database",
name="id-type",
havingValue="HU_TOOL")
public UidGenerator getHuToolUidGenerator()
@Bean public LeftLikeTypeHandler getLeftLikeTypeHandler()
eg: and name like #{name,typeHandler=leftLike}
@Bean public RightLikeTypeHandler getRightLikeTypeHandler()
eg: and name like #{name,typeHandler=rightLike}
@Bean public FullLikeTypeHandler getFullLikeTypeHandler()
eg: and name like #{name,typeHandler=fullLike}
@Bean @ConditionalOnMissingBean public LampSqlInjector getMySqlInjector()
Copyright © 2022. All rights reserved.