controller:
@GetMapping("/users")
public String users(Model model,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "5") Integer size){
List<UserInfo> users=this.userService.findAll(page,size);
PageInfo<UserInfo> pageInfo=new PageInfo<>(users);
model.addAttribute("users",pageInfo);
return "user-list";
}
userservice:
List<UserInfo> findAll(Integer page,Integer size);
impl:
@Override
public List<UserInfo> findAll(Integer page,Integer size) {
PageHelper.startPage(page,size);
return this.userMapper.findAll();
}
页面:
<ul class="pagination">
<li><a th:href="@{/users(page=1,size=5)}">首页</a></li>
<li><a th:href="@{/users(page=${users.pageNum - 1},size=5)}">上一页</a></li>
<li th:each="pageNums :${#numbers.sequence(users.firstPage,users.lastPage)}">
<a th:href="@{/users(page=${pageNums},size=5)}" th:text="${pageNums}"></a>
</li>
<li><a th:href="@{/users(page=${users.pageNum + 1},size=5)}">下一页</a></li>
<li><a th:href="@{/users(page=${users.pages},size=5)}">尾页</a></li>
</ul>