
private String homeInfo(Model model) { Page<PostEntity> postEntities= postService.findAllByPage(0,10); model.addAttribute("posts",postEntities.getContent()); int totalPage=postEntities.getTotalPages(); int nowPage=postEntities.getPageable().getPageNumber()+1; int prePage=nowPage>2?nowPage-1:0; int nextPage=nowPage<totalPage?nowPage+1:0; model.addAttribute("totalPage",totalPage); model.addAttribute("nowPage",nowPage); model.addAttribute("prePage",prePage); model.addAttribute("nextPage",nextPage); return render("index"); } <!--分页--> <div style="text-align: center"> <a class="pure-button" href="/">首页</a> <a class="pure-button" th:if="${prePage != 0}" th:href="@{‘/page/‘+${prePage}}">上一页</a> <a class="pure-button" th:if="${nextPage != 0}" th:href="@{‘/page/‘+${nextPage}}">下一页</a> <a class="pure-button" th:href="@{‘/page/‘+${totalPage}}">尾页</a> </div>springboot+thymeleaf 纯后台渲染偷懒版分页
原文:https://www.cnblogs.com/tilv37/p/9365430.html