①在主配文件中添加
<?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>
<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>
②在需要的地方添加使用(PageResult可以自己封装,注意实现序列化接口,Long total List rows)
@Override
public PageResult findPage(Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum,pageSize);
Page<TbBrand> page=(Page<TbBrand>) brandMapper.selectByExample(null);
PageResult pageResult = new PageResult(page.getTotal(), page.getResult());
return pageResult;
}