spring boot结合easyui分页展示数据

分析:easyui 每次请求分页控件的时候会向后台传page(当前的页码数),和rows(每页记录的大小)这两个参数,

前台接收的数据参数需要总记录数(total)和每页的记录数据集合(rows).

      后台只需查出总记录数和对象数据传向前台,easyui就会自动处理,下面看详细操作

前台部分很简单,只需开启分页控件pagination:true ;

$(function(){
    $("#list").datagrid({
        url:"getLiveVideoInfo",
        columns:[[
            {field:"mobile",align:'center',title:"手机号码",width:200},
            {field:"nick",align:'center',title:"昵称",width:200},
            {field:"age",align:'center',title:"年龄",width:200},
        ]],
        //分页工具
        pagination:true,
        //工具条件
        toolbar:"#toolbar"
    });

如果遇到数据显示不出来,请在colums:[[  的下一行进行空行

另外一种解决方式:在<script type="text/javascript"></script>添加

<script type="text/javascript"  th:inline="none"></script>
需引入:
<html  lang="en" xmlns:th="http://www.thymeleaf.org">

此处不明白的看客可以加群:244284555  进行交流

spring boot 代码:

/**
 * @param page 当前的页数
 * @param rows 每页记录大小
 * @return
 */
@RequestMapping(value = "/getLiveVideoInfo",method = RequestMethod.POST)
public Map getLiveVideoInfo(Integer page, Integer rows){

    //查询所有数据
    List<MwMediaLiveVideo> mwMediaLiveVideosList = mwMediaLiveVideoRepository.findAll();
    //查询总记录数
    Long total = mwMediaLiveVideoRepository.findByTotalCount();
    //展示分页集合
    List<MwMediaLiveVideo> mwMediaLiveVideos = new ArrayList<>();

    for (int i = 0; i < mwMediaLiveVideosList.size(); i++)
    {
        //当前页-1 * 记录数 并且 这条记录是第几页的数据 当前页乘以记录数
        //第一次传过来的rows 是10 page是1
        if (i >= (page - 1) * rows && i < page * rows)
        {
            //符合当前页的数据添加到展示分页集合中
            mwMediaLiveVideos.add(mwMediaLiveVideosList.get(i));
        }
    }
    Map<String,Object> result = new HashMap<String,Object>();
    result.put("total", total);
    result.put("rows", mwMediaLiveVideos);
    return result;

}

我觉得这个分页已经做的非常之简单,明白page,rows,total 这三个参数的含义就很好理解

猜你喜欢

转载自blog.csdn.net/qq_28524127/article/details/82625216