• springboot:使用pagehelper之后,无法添加自定义mybatis拦截器


    1.实现自定义mybatis拦截器

    @Component
    @Intercepts({ @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) })
    public class MybatisInterceptor implements Interceptor {
    
    // 略......
    
    }

    2.在web listener中添加这个拦截器

    @Component
    public class StartSysListener implements ApplicationListener<ContextRefreshedEvent> {
    
      private static Logger log = LoggerFactory.getLogger(StartSysListener.class);
      
      @Autowired
      private MybatisInterceptor mybatisInterceptor;
      @Autowired
      private List<SqlSessionFactory> sqlSessionFactoryList;
    
    
      @Override
      public void onApplicationEvent(ContextRefreshedEvent event) {
    
        this.addMyInterceptor();
    
      }
    
      private void addMyInterceptor() {
        log.debug("添加自定义Mybatis SQL拦截器.");
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
          sqlSessionFactory.getConfiguration().addInterceptor(mybatisInterceptor);
        }
      }
    
    }


    这种方式添加简单,易于使用。

  • 相关阅读:
    141. Linked List Cycle【easy】
    237. Delete Node in a Linked List【easy】
    234. Palindrome Linked List【easy】
    排序_归并排序
    排序_选择排序
    排序_快速排序
    排序_冒泡排序
    排序_希尔排序
    排序_插入排序
    121. Best Time to Buy and Sell Stock【easy】
  • 原文地址:https://www.cnblogs.com/huiy/p/13354528.html
Copyright © 2020-2023  润新知