1、如果你使用的是 springBoot 那么应该引入下面的依赖 (版本号自己确定)
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
2、SpringMvc里面引入下面的依赖(版本号自己确定)
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
3、如果你非要在SpringBoot中引入下面这种,那么你需要配置一个拦截器
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
PageInterceptor
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import java.util.Properties;
@Intercepts(
{
@Signature(type = Executor.class, method = "query", args = {
MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
@Signature(type = Executor.class, method = "query", args = {
MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
}
)
public class PageInterceptor extends com.github.pagehelper.PageInterceptor{
public PageInterceptor(){
super();
Properties properties = new Properties();
properties.setProperty("dialect", "com.github.pagehelper.PageHelper");
setProperties(properties);
}
}
我们是在多数据源配置的时候加上的,你可以根据实际情况来。
public DataSource primaryDataSource() {
DataSource ds = DataSourceBuilder.create().build();
ADOSessionImpl session = new ADOSessionImpl();
//开启/关闭-自动转换驼峰标识
SessionFactory.setMapUnderscoreToCamelCase(true);
session.addInterceptor("_default", "com.koron.util.PageInterceptor");
session.registeDataSourceMap("_default", ds);
return ds;
}