Git Product home page Git Product logo

Comments (5)

cookier avatar cookier commented on May 23, 2024 5

经过断点调试发现,需要以下配置:

<bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>dialect=</value>
                    </property>
                </bean>

根据我的观察,PageIntercepor.setProperties方法里是设置dialect属性值的,如果在配置文件中没有调用到setProperties方法,则dialect为空,也没有默认值,所以导致执行插件的intercept方法时,调用dialect.afterAll()方法发生NPE。

from mybatis-pagehelper.

cookier avatar cookier commented on May 23, 2024 3

生成XMLConfigBuilder的前提是有mybatis的配置文件,可我是用spring的属性配置方式。这样在SqlSessionFactoryBean.buildSqlSessionFactory的方法里由于configLocation属性值为空,不会生成xmlConfigBuilder对象,所以都不会执行到pluginElement方法。

from mybatis-pagehelper.

abel533 avatar abel533 commented on May 23, 2024

正常配置的情况下,只有用 pagehelper-starter 1.0.0 版本才会出现。

单独的分页插件,只有配置多次才会出现。

from mybatis-pagehelper.

abel533 avatar abel533 commented on May 23, 2024

XMLConfigBuilder 中:

private void pluginElement(XNode parent) throws Exception {
    if (parent != null) {
      for (XNode child : parent.getChildren()) {
        String interceptor = child.getStringAttribute("interceptor");
        Properties properties = child.getChildrenAsProperties();
        Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
        interceptorInstance.setProperties(properties);
        configuration.addInterceptor(interceptorInstance);
      }
    }
  }

源码中,不管 properties 是否有值,都会执行 setProperties 方法,不是你说的问题。你可以看看这里。

from mybatis-pagehelper.

abel533 avatar abel533 commented on May 23, 2024

非常感谢!!
确实有这个问题。
后面我会考虑在 public Object plugin(Object target) 方法中初始化插件。

from mybatis-pagehelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.