springboot pagehelper thymeleaf分页详细代码讲解,上一页,下一页,页码遍历,省略号

1.后台返回的数据

@RequestMapping("/bourse")
    public ModelAndView bourse(Model model, Integer pageNum) {
        List<DicType> dicTypes = dicTypeService.showAlL();
        model.addAttribute("area", dicTypes);
        PageInfo<Map<String, Object>> page = bourseService.findItemByPage(pageNum, 50);
        model.addAttribute("bourse", page);
        return new ModelAndView("bourse");
    }

在这里插入图片描述
2.前端封装

<!--        上一页-->
        <!--        如果为第一页,则没有a标签-->
        <th:block th:if="${bourse.pageNum==1}">
            <span class="last"></span>
        </th:block>
        <th:block th:if="${bourse.pageNum>1}">
            <a th:href="@{/bourse(pageNum=${bourse.pageNum-1})}">
                <span class="last"></span></a>
        </th:block>
        <!--        页码遍历-->
        <th:block th:each="i :${#numbers.sequence(1, bourse.pages)}">
            <a th:href="@{/bourse(pageNum=${i})}">
                <!--                当前页样式为on-->
                <span th:class="${bourse.pageNum == i}? 'on' :''">
                <th:block th:text="${i}"></th:block>
            </span>
            </a>
        </th:block>
        <!--下一页-->
        <!--        如果为最后一页也没有a标签-->
        <th:block th:if="${bourse.pageNum==bourse.pages}">
            <span class="next"></span>
        </th:block>
        <th:block th:if="${bourse.pageNum<bourse.pages}">
            <a th:href="@{/bourse(pageNum=${bourse.pageNum+1})}">
                <span class="next"></span>
            </a>
        </th:block>
    </div>
</div>

在这里插入图片描述
3.效果,css自己写
在这里插入图片描述

发布了62 篇原创文章 · 获赞 21 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40618664/article/details/100553176