springboot+layui如何实现表格分页
时间: 2023-02-21 07:55:35 浏览: 43
在 Spring Boot 项目中实现 layui 表格分页的方法如下:
1. 前端:在使用 layui 表格的页面中,使用 layui 提供的分页模块实现表格的分页。
2. 后端:在 Spring Boot 项目的后端代码中,通过实现分页查询的功能,并将分页结果以 JSON 格式返回给前端。
举个例子:
前端代码:
```html
<table id="dataTable"></table>
<script>
layui.use(['table', 'laypage'], function(){
var table = layui.table;
var laypage = layui.laypage;
//展示已知数据
table.render({
elem: '#dataTable'
,cols: [[ //标题栏
{field: 'id', title: 'ID', width: 80, sort: true}
,{field: 'username', title: '用户名', width: 80}
,{field: 'sex', title: '性别', width: 80, sort: true}
,{field: 'city', title: '城市', width: 80}
,{field: 'sign', title: '签名', width: 177}
,{field: 'experience', title: '积分', width: 80, sort: true}
,{field: 'score', title: '评分', width: 80, sort: true}
,{field: 'classify', title: '职业', width: 80}
,{field: 'wealth', title: '财富', width: 135, sort: true}
]]
,data: []
,page: true
,limit: 10
,limits: [10, 20, 30, 40, 50]
,request: {
pageName: 'curr' //页码的参数名称,默认:page
,limitName: 'nums' //每页数据量的参数名,默认:limit
}
,response: {
statusCode: 200 //成功的状态码,默认:0
}
,done: function(res, curr, count){
//如果是异步请求数据方