注意还需要在applicationContext.xml中添加
<!-- session工厂--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- com.wzx.domain.Person person--> <property name="typeAliasesPackage" value="com.wzx.domain"/> <property name="configLocation" value="classpath:SqlMapConfig.xml"/> </bean>两种方式,根据个人习惯任选一个。
原理在拦截器 以下是模拟代码:
select count(*) from department select * from department limit 0, 20 ;//第一页 select * from department limit 20, 20 ;//第二页 select * from department;//由拦截器 PageInterceptor生成以上sql由于拦截器会使用全查语句拼接limit分页,所以每个sql建议不要写; 先调用PageHelper.start(1,10)再调用全查,才能自动分页
》》导入c标签 使用里面的foreach与if标签 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 》》循环列表的行
<div class="row"> <div class="col-md-12"> <table class="table table-hover"> <tr> <th>部门编号</th> <th></th> <th>部门名称</th> <th>操作</th> </tr> <c:forEach items="${pi.list}" var="dept"> <!--将一行循环指定的次数 --> <tr> <td>${dept.did}</td> <td></td> <td>${dept.dname}</td> <td> <button class="btn btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除 </button> <button class="btn btn-info"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改 </button> </td> </tr> </c:forEach> </table> </div> </div>》》赋值显示分页工具条
<div class="row"> <div class="col-md-6">当前共有${pi.total}条记录,共${pi.pages}页</div> <div class="col-md-6"> <nav aria-label="Page navigation"> <ul class="pagination"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">首页</span> </a> </li> <c:if test="${pi.hasPreviousPage}"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">上一页</span> </a> </li> </c:if> <%-- <li class="active"><a href="#">1</a></li>--%> <c:forEach items="${pi.navigatepageNums}" var="num"> <c:if test="${num == pi.pageNum}"> <li class="active"><a href="#">${num}</a></li> </c:if> <c:if test="${num != pi.pageNum}"> <li><a href="#">${num}</a></li> </c:if> </c:forEach> <c:if test="${pi.hasNextPage}"> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">下一页</span> </a> </li> </c:if> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">末页</span> </a> </li> </ul> </nav> </div> </div>