mybatisplus分页以后,前端无法分页
时间: 2023-11-17 20:03:34 浏览: 35
Mybatis-plus提供了内置的分页功能,但是前端需要手动实现分页逻辑。具体来说,前端需要在页面上添加分页组件,并且在每次请求后端数据时,将当前页码和每页显示的数据条数作为参数传递给后端。后端根据这些参数进行分页查询,并将查询结果返回给前端。前端再根据返回的数据渲染分页组件。
以下是一个示例代码,展示了如何在前端使用Thymeleaf模板引擎实现分页逻辑:
```html
<!-- 分页组件 -->
<div class="pagination">
<ul>
<li th:class="${pageInfo.hasPreviousPage} ? '' : 'disabled'">
<a th:href="@{/list(pageNum=1)}">«</a>
</li>
<li th:each="page: ${pageInfo.navigatepageNums}"
th:class="${page} == ${pageInfo.pageNum} ? 'active' : ''">
<a th:href="@{/list(pageNum=${page})}" th:text="${page}"></a>
</li>
<li th:class="${pageInfo.hasNextPage} ? '' : 'disabled'">
<a th:href="@{/list(pageNum=${pageInfo.pages})}">»</a>
</li>
</ul>
</div>
<!-- 数据展示 -->
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
</thead>
<tbody>
<tr th:each="user: ${pageInfo.list}">
<td th:text="${user.name}"></td>
<td th:text="${user.age}"></td>
</tr>
</tbody>
</table>
```
在上面的代码中,分页组件使用了Bootstrap样式,并且使用Thymeleaf的循环语句动态生成页码。数据展示部分使用了Thymeleaf的表达式语言将后端返回的数据渲染到页面上。