1.引架包。注意版本问题git
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.6</version>
</dependency>
2.在MyBatis 的整体文件中配置插件github
放到<environments default="development">以前 <plugins> <!-- PageHelper4.1.6 --> <plugin interceptor="com.github.pagehelper.PageHelper"> <property name="dialect" value="oracle"/> </plugin> </plugins> 插件5.1之后interceptor不一样,而且不须要指定数据库名字 <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> </plugin> </plugins>
3.在service层返回值类型是pageInfo,数据库
4.在实现类中mybatis
@Override public PageInfo getall(String classname, String classnum, int pageindex, int size,int[] ids,String classstate) { //封装模糊查条件 Map map =new HashMap(); map.put("classname",classname); map.put("classnum",classnum); map.put("ids",ids); map.put("classstate",classstate); //使用PageInfo工具实现分页,一、导架包二、配置mybatis.xml PageHelper.startPage(pageindex,size);//在执行查询以前设置 List list = classesMapper.getall(map); //将插入的集合存在PageInfo分页工具中 PageInfo pi = new PageInfo(list); return pi; }
5.得到其余分页的信息oracle
System.out.println("总条数="+pi.getTotal()); System.out.println("总页数="+pi.getPages()); System.out.println("下一页="+pi.getNextPage()); System.out.println("当前页码="+pi.getPageNum()); System.out.println("每页显示条数:"+pi.getPageSize());