mybaits分页插件的使用

1.导入依赖坐标

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
2.在配置文件中配置

<configuration>
<plugins>
<!-- com.github.pagehelper 为 PageHelper 类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL 六种 数据库—>
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration>

3.使用分页插件
@Override
public PageResult findAll(QueryPageBean queryPageBean) {
Integer pageSize = queryPageBean.getPageSize();
String queryString = queryPageBean.getQueryString();
Integer currentPage = queryPageBean.getCurrentPage();
PageHelper.startPage(currentPage,pageSize);
Page<CheckGroup> all = checkGroupDao.findAll(queryString);
return new PageResult(all.getTotal(),all.getResult());
}

如果想获得更多的信息,可以用pageInfo、
PageInfo<CheckGroup> pageInfo = new PageInfo<CheckGroup>(all)

猜你喜欢

转载自www.cnblogs.com/shangyunlin/p/12321569.html