Controller层
@Controller
@RequestMapping
public class IndexController {
@Autowired
private EmployeeService employeeService;
@RequestMapping
public String list(Model model, String name,
@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum){
PageHelper.startPage(pageNum,5);
List<Employee> list = employeeService.list(name);
PageInfo<Employee> pageInfo = new PageInfo<Employee>(list);
model.addAttribute("page",pageInfo);
return "home";
}
}
Jsp页面
<tr>
<td colspan="8">
<c:if test="${!page.isFirstPage}">
<a href="/?pageNum=${page.prePage}">上一页</a>
</c:if>
<c:forEach begin="1" end="${page.pages}" varStatus="index">
<a href="/?pageNum=${index.index}">${index.index}</a>
</c:forEach>
<c:if test="${!page.isLastPage}">
<a href="/?pageNum=${page.nextPage}">下一页</a>
/c:if>
</td>
</tr>