后端分页实例

废话不多说,先看效果图!

直接上代码:

前端页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
 
<title>分页测试</title>
 
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
 
 
<link rel="stylesheet" href="fpage/layui/css/layui.css"  media="all">
<script src="fpage/layui/layui.all.js" charset="utf-8"></script>
<script src="fpage/layui/lay/modules/laypage.js" charset="utf-8"></script>
<script src="components/plugin/jquery/jquery-1.6.0.js" charset="utf-8"></script>
 
<script>
$(document).ready(function(){
    //表格初始化
    $.ajax({
        type:"post",
        url:"SingerController/getInfo.do",//对应controller的URL
           success:function(json){
               var total=json;
               initFPage(total);
           }
    });
     
  })
    //分页器
    function initFPage(total){
        layui.use('laypage', function(){
        var laypage = layui.laypage;
         laypage.render({
              elem: 'page', //注意,这里的 page 是 ID,不用加 # 号
              //数据总数,从服务端得到
              limits:[10,20,30,40,50],
              prev:"<<",
              next:">>",
              theme:"#0099ff",
              layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
              count:total,//总记录数
              curr:1,//初始化选中的页码
              limit:10,//每页显示记录数
              jump:function(layinit){
                  $.ajax({
                      type:"post",
                      url:"SingerController/getInfo222.do",//对应controller的URL
                      data:{
                          "page":layinit.curr,//当前页码
                          "size":layinit.limit},//请求每页数据记录数;
                          success:function(json){
                              var list=json;
                              //初始化table页面
                              var tr="";
                              for(var j=0;j < list.length;j++){
                              tr+='<td>'+list[j].singerName+'</td>';
                              }
                              $("#tbody").html(tr);
                      }
                  });
              }
         });
 
        });
    }
</script>
</head>
 
<body>
    <div class=" table-second">
        <div class="table-container">
            <table class="layui-table" id="initInfo">
                <thead id="thead">
                </thead>
                <tbody id="tbody">
                </tbody>
            </table>
        </div>
    </div>
    <div id="page" style="text-align:right"></div>
</body>
</html>

控制层:

package com.hgs.amusicweb.controller;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletResponse;
 
import net.sf.json.JSONArray;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.hgs.amusicweb.biz.SingerBiz;
import com.hgs.amusicweb.pojo.SingerPojo;
 
//歌手页面
@Controller
@RequestMapping("/SingerController")
public class SingerController {
    @Autowired
    private SingerBiz singerBiz;
     
    @RequestMapping(value = "/getInfo")
    public void inborrowInfo(,HttpServletResponse response)
            throws IOException {
        //查询总记录数
        response.getWriter().print(singerBiz.queryCount());
    }
@RequestMapping(value = "/getInfo222")
    public void inborrowInfo(Integer page,Integer size,HttpServletResponse response)
            throws IOException {
        if(page!=null&&size!=null){
            //查询当前页记录数据
            List<SingerPojo> querySingerListLimit = singerBiz.querySingerListLimit(page,size);
            JSONArray json = JSONArray.fromObject(querySingerListLimit );
            response.getWriter().print(json);
        }
    }
}
后面的代码就只能靠自己了,哈哈。
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
本门课程重实战,将基础知识拆解到项目里,让你在项目情境里学知识。 这样的学习方式能让你保持兴趣、充满动力,时刻知道学的东西能用在哪、能怎么用。 平时不明白的知识点,放在项目里去理解就恍然大悟了。   一、融汇贯通 本视频采用了前后端分离的开发模式,前端使用Vue.js+Element UI实现了Web页面的呈现,后端使用Python 的Django框架实现了数据访问的接口,前端通过Axios访问后端接口获得数据。在学习完本章节后,真正理解前后端的各自承担的工作。   二、贴近实战 本系列课程为练手项目实战:学生管理系统v4.0的开发,项目包含了如下几个内容:项目的总体介绍、基本功能的演示、Vuejs的初始化、Element UI的使用、在Django中实现针对数据的增删改查的接口、在Vuejs中实现前端增删改查的调用、实现文件的上传、实现表格的分页、实现导出数据到Excel、实现通过Excel导入数据、实现针对表格的批量化操作等等,所有的功能都通过演示完成、贴近了实战   三、课程亮点 在本案例中,最大的亮点在于前后端做了分离,真正理解前后端的各自承担的工作。前端如何和后端交互   适合人群: 1、有Python语言基础、web前端基础,想要深入学习Python Web框架的朋友; 2、有Django基础,但是想学习企业级项目实战的朋友; 3、有MySQL数据库基础的朋友  
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值