<div class="col-md-6">
<nav aria-label="Page navigation">
<ul class="pagination">
<li><a href="${APP_PATH }/emps?pn=1">首页</a></li>
<li>
<c:if test="${pageInfo.hasPreviousPage}" >
<a href="${APP_PATH }/emps?pn=${pageInfo.pageNum-1}" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</c:if>
</li>
<c:forEach items="${pageInfo.navigatepageNums}" var="page_Num">
<c:if test="${page_Num == pageInfo.pageNum}">
<li class="active"><a href="#">${page_Num }</a></li>
</c:if>
<c:if test="${page_Num != pageInfo.pageNum}">
<li ><a href="${APP_PATH }/emps?pn=${page_Num }">${page_Num }</a></li>
</c:if>
</c:forEach>
<li>
<c:if test="${pageInfo.hasNextPage}" >
<a href="${APP_PATH }/emps?pn=${pageInfo.pageNum+1 }" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</c:if>
</li>
<li><a href="${APP_PATH }/emps?pn=${pageInfo.pages }">末页</a></li>
</ul>
</nav>
</div>
</div>
package com.controller;
import com.bean.Employee;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Controller
public class EmpController {
@Autowired
EmpService empService;
@RequestMapping("/emps")
public String emp(
@RequestParam(value = "pn", defaultValue = "1") Integer pn,
Map<String,Object> map) {
//pn第一页传入的当前页,每页显示5数据
PageHelper.startPage(pn, 5);
//查询数据
List<Employee> emps = empService.getAll();
map.put("emps",emps);
//封装,当前页有连续的5条
PageInfo page = new PageInfo(emps,5);
map.put("pageInfo",page);
return "list";
}
}
