Encountered type conversion exception when configured PageHelper plug-in project

PageHelper tab is a common tool, its integration in conventional manner mybatis configuration file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

    <!--全局环境参数-->
    <settings>
        ...
    </settings>

    <!--插件配置-->
    <plugins>
        <!--支持PageHelper插件-->
        <plugin interceptor="com.github.pagehelper.PageHelper">
            ...
        </plugin>
    </plugins>

</configuration>

 

When starting the service, but it throws the following exception:

Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor

 

See literally translation exception type, PageHelper not be converted into org.apache.ibatis.plugin.Interceptor, then the point source into PageHelper

/ ** 
 * Mybatis - general tab interceptor a 
 * LOCATION: http://git.oschina.net/free/Mybatis_PageHelper 
 * 
 * @author liuzh / abel533 / isea533 
 * @version 5.0.0
  * / 
public  class PageHelper the extends PageMethod the implements the Dialect { 
    ... 
}

 

Does not implement Interceptor there Dian mystery, because the previous project is so configured, why not out of this problem?

Find old project sites into PageHelper Source:

/**
 * Mybatis - 通用分页拦截器
 *
 * @author liuzh/abel533/isea533
 * @version 3.3.0
 *          项目地址 : http://git.oschina.net/free/Mybatis_PageHelper
 */
@SuppressWarnings("rawtypes")
@Intercepts(@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}))
public class PageHelper implements Interceptor {
    ...
}

 

The reason found:

PageHelper3,4 version implements Interceptor interfaces, PageHelper5 no longer achieved.

So the question is, if you use PageHelper5 version, how in mybatis inherit this plug-in? From com.github.pagehelper package PageHelper located, we found a class called PageInterceptor, whose name has Dian like what we're looking for, point source into a look, really realize the Interceptor interface.

 

 

So we try to put this class mybatis configuration file, delete the property does not exist, start the service normally.

Conclusion: Use PageHelper version 3, 4, PageHelper mybatis class in the configuration file using integrated, using PageHelper version 5, using integrated mybatis PageInterceptor class profile.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

    <!--全局环境参数-->
    <settings>
        ...
    </settings>

    <!--插件配置-->
    <plugins>
        <!--支持PageHelper插件-->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
        </plugin>
    </plugins>

</configuration>

 

Guess you like

Origin www.cnblogs.com/dubhlinn/p/10932261.html