MyBatis 插件失效
public class BaseMybatisPlusConfig {
/**
* Mybatis 实现分页
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
DbType dbType = DbType.MYSQL;
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(dbType));
return interceptor;
}
}
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;
/**
* 注册 Bean
*/
@Component
public class MyBeanFactoryInvoke implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
RootBeanDefinition beanDefinition = new RootBeanDefinition(MyInterceptor.class);
beanDefinitionRegistry.registerBeanDefinition("MyInterceptor", beanDefinition);
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
}
}
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import java.util.concurrent.Executor;
@Intercepts({
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class})
})
public class MyInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
System.out.println("----------MyInterceptor----------");
return invocation.proceed();
}
}
/**
* MybatisPlus 源码
*/
public MybatisPlusAutoConfiguration(){
...
if (!ObjectUtils.isEmpty(this.interceptors)) {
factory.setPlugins(this.interceptors);
}
...
}
执行顺序:先执行 MyInterceptor ,再 通过 invocation.proceed(); 执行 MybatisPlusInterceptor
本文作者:笔兴洽谈室 哔哩哔哩:笔兴洽谈室 GitHub:StarJava1024 Gitee:StarJava1024
本文链接:https://www.cnblogs.com/CrayonXiaoxing/articles/17900462.html
原创文章仅用于学习,不得修改原作品,不得再创作。若本文侵犯某版权,请私信联系删除!如需转载,请私信!