PageHelperhttps://github.com/pagehelper/Mybatis-PageHelper
//当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int size; //由于startRow和endRow不常用,这里说个具体的用法 //可以在页面中"显示startRow到endRow 共size条数据" //当前页面第一个元素在数据库中的行号 private int startRow; //当前页面最后一个元素在数据库中的行号 private int endRow; //总记录数 private long total; //总页数 private int pages; //结果集 private List<T> list; //第一页 private int firstPage; //前一页 private int prePage; //是否为第一页 private boolean isFirstPage = false; //是否为最后一页 private boolean isLastPage = false; //是否有前一页 private boolean hasPreviousPage = false; //是否有下一页 private boolean hasNextPage = false; //导航页码数 private int navigatePages; //所有导航页号 private int[] navigatepageNums;
Config PageHelper
1. Using in mybatis-config.xml
<plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <property name="param1" value="value1"/> </plugin> </plugins>
2. Using in Spring application.xml
config org.mybatis.spring.SqlSessionFactoryBean as following:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- other configuration --> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!-- config params as the following --> <value> param1=value1 </value> </property> </bean> </array> </property> </bean>
@Service public class DocServiceImpl implements IDocService { @Autowired private DocMapper docMapper; @Override public PageInfo<Doc> selectDocByPage1(int currentPage, int pageSize) { PageHelper.startPage(currentPage, pageSize); List<Doc> docs = docMapper.selectByPageAndSelections(); PageInfo<Doc> pageInfo = new PageInfo<>(docs); return pageInfo; } }
原文:https://www.cnblogs.com/ican-fly/p/11180392.html