pagehelper / pagehelper-spring-boot

pagehelper-spring-boot
MIT License
1.55k stars 312 forks source link

在项目中使用热部署,starter中的PageHelperAutoConfiguration会重复添加PageInterceptor #149

Open Owen-s1eep opened 2 years ago

Owen-s1eep commented 2 years ago

com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration#containsInterceptor 判断是否注册过拦截器,应该判断下class,而不是实例吧?每次都是PageInterceptor interceptor = new PageInterceptor(); 新创建的,肯定不一样。或者可以考虑重写PageInterceptor中的equals和hashcode方法去做判断?

问题方法

public void afterPropertiesSet() throws Exception {
        PageInterceptor interceptor = new PageInterceptor();
       ...
        while(var2.hasNext()) {
           ...
            if (!this.containsInterceptor(configuration, interceptor)) {
                configuration.addInterceptor(interceptor);
            }
        }

    }
 private boolean containsInterceptor(org.apache.ibatis.session.Configuration configuration, Interceptor interceptor) {
        try {
            return configuration.getInterceptors().contains(interceptor);
        } catch (Exception var4) {
            return false;
        }
    }