赞
踩
<!-- 添加分布插件的包pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
<!--配置sqlsession factory--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!--加载mybatis的核心文件--> <property name="configLocation" value="classpath:sqlMapConfig-spring.xml"></property> <!--融合mybatis 不需要mapper的映射文件--> <property name="mapperLocations" value="classpath:com.demo.entity/*Mapper.xml"></property> <!--分页插件--> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <value> offsetAsPageNum=true rowBoundsWithCount=true pageSizeZero=true reasonable=true </value> </property> </bean> </array> </property> </bean>
<select id="selectpage" resultType="users" parameterType="Integer">
select * from users
</select>
@RequestMapping("/selectallpage2") public String selectallpage2(users users, Model model, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){ PageHelper.startPage(2,10);//startPage是告诉拦截器说我要开始分页了。分页参数是这两个。 List<users> page = us.selectpage(users, pageNum, pageSize); PageInfo<users> pageInfo = new PageInfo<>(page);//对普通的page查询到的进行增强 model.addAttribute("pageInfo",pageInfo); for (users users1 : pageInfo.getList()) { System.out.println(users1.getId()+"===="+users1.getUname()); } System.out.println("总行数="+pageInfo.getTotal()); System.out.println("当前页="+pageInfo.getPageNum()); System.out.println("每页行数="+pageInfo.getPageSize()); System.out.println("总页数="+pageInfo.getPages()); System.out.println("起始行数="+pageInfo.getStartRow()); System.out.println("是第一页="+pageInfo.isIsFirstPage()); System.out.println("是最后一页="+pageInfo.isIsLastPage()); System.out.println("还有下一页="+pageInfo.isHasNextPage()); System.out.println("还有上一页="+pageInfo.isHasPreviousPage()); System.out.println("页码列表="+ Arrays.toString(pageInfo.getNavigatepageNums())); return "select"; }
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title></title> </head> <body> <h1>查询全部</h1> <table> <thead> <tr> <td>编号</td> <td>姓名</td> <td>密码</td> </tr> </thead> <c:forEach var="list" items="${pageInfo.list}" <tbody> <tr> <td>${list.id}</td> <td>${list.uname}</td> <td>${list.pwd}</td> </tr> </tbody> </c:forEach> </table> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。