注意

使用的layui版本为:layui-v2.0以上版本,如果v1.0版本请看我另外一篇博客 《layui完美分页,ajax请求分页(真分页)》

最近因为以为学者在看了我上一篇关于layui分页的博客遇到了问题,原因是因为使用了新版本2.x,导致有一些属性改变了,所以出了这篇新版本的博客,本文是根据上一篇博客改变而成,如有疑问请联系我 email:1085143002@qq.com

完整代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta name="renderer" content="webkit">
    <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <Meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <Meta name="apple-mobile-web-app-status-bar-style" content="black">
    <Meta name="apple-mobile-web-app-capable" content="yes">
    <Meta name="format-detection" content="telephone=no">
    <link rel="icon" href="static/images/titlelogo.png" />
    <title>门店管理后台</title>
    <link rel="stylesheet" href="static/layui/plugins/layui/css/layui.css" media="all" />
    <!-- <link rel="stylesheet" type="text/css" href="static/css/reset.css"> <link rel="stylesheet" type="text/css" href="static/css/commend.css"> -->
    <!-- <link rel="stylesheet" href="static/css/jqpagination.css" /> -->
    <!-- <link rel="stylesheet" type="text/css" href="static/css/shopCustomerManager.css"> -->
    <script type="text/javascript" src="static/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="static/layui/plugins/layui/layui.js"></script>
    <!-- <script type="text/javascript" src="static/js/jquery.jqpagination.js"></script> -->
    <script type="text/javascript"> $(document).ready(function(){ //ajax请求后台数据 getShopCustomerManagePageInfo(); //点击搜索时 搜索数据 $("#selectButton").click(function(){ getShopCustomerManagePageInfo(); currentPageAllAppoint = 1; //当点击搜索的时候,应该回到第一页 toPage();//然后进行分页的初始化 }) toPage(); }); //分页参数设置 这些全局变量关系到分页的功能 var startAllAppoint = 0;//开始页数 var limitAllAppoint = 10;//每页显示数据条数 var currentPageAllAppoint = 1;//当前页数 var dataLength = 0;//数据总条数 //ajax请求后台数据 function getShopCustomerManagePageInfo(){ $.ajax({ type:"post",async:false,url:"list_shop_customers_info",data:{start:startAllAppoint,limit:limitAllAppoint,selectValue:$("#selectValue").val()},success:function(data,status){ data=eval("("+data+")"); getShopCustomesInfo(data.root); startAllAppoint = data.currentResult;//当前页数(后台返回) dataLength = data.total;//数据总条数 } }); } function getShopCustomesInfo(data){ var s = "<tr><th>姓名</th><th>性别</th><th>电话</th><th>备案楼盘</th><th>已成交</th><th>归属经纪人</th><th>添加时间</th></tr>"; $.each(data,function(v,o){ s+='<tr><td>'+o.cusName+'</td>'; s+='<td>'+o.cusSex+'</td>'; s+='<td>'+o.phone+'</td>'; s+='<td>'+o.records+'</td>'; s+='<td>'+o.alreadyDeal+'</td>'; s+='<td>'+o.theMedi+'</td>'; s+='<td>'+o.addTime+'</td></tr>'; }); if(data.length>0){ $("#t_customerInfo").html(s); }else{ $("#page1").hide(); $("#t_customerInfo").html("<br/><span style='width:10%;height:30px;display:block;margin:0 auto;'>暂无数据</span>"); } } function toPage(){ layui.use(['form','laypage','layedit','layer','laydate'],function() { var form = layui.form(),layer = layui.layer,layedit = layui.layedit,laydate = layui.laydate,laypage = layui.laypage; var nums = 10; //调用分页 laypage({ cont: 'paged',count: dataLength //这个是后台返回的数据的总条数,limit: limitAllAppoint //每页显示的数据的条数,layui会根据count,limit进行分页的计算,curr: currentPageAllAppoint,skip: true,jump: function(obj,first){ currentPageAllAppoint = obj.curr; startAllAppoint = (obj.curr-1)*obj.limit; //document.getElementById('biuuu_city_list').innerHTML = render(obj,obj.curr); if(!first){ //一定要加此判断,否则初始时会无限刷新 getShopCustomerManagePageInfo();//一定要把翻页的ajax请求放到这里,不然会请求两次。 //location.href = '?page='+obj.curr; } } }); }); }; </script>
</head>
<body>
    <div class="admin-main">


                <blockquote class="layui-elem-quote">
                <form class="layui-form" action="" >
                <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" id="selectValue" lay-verify="required" placeholder="客户姓名,电话" autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn" type="button" id="selectButton">搜索</button>
                </div>
                </form>
                <span><a href="shop_customer_manager_page_info">显示所有客户</a></span>
                </blockquote>
                <fieldset class="layui-elem-field">
                    <legend>客户列表</legend>
                    <div class="layui-field-Box layui-form">
                        <table class="layui-table admin-table" id="t_customerInfo">

                        </table>
                    </div>
                </fieldset>
                <div class="admin-table-page">
                    <div id="paged" class="page">
                    </div>
                </div>
            </div>


</body>
</html>

java代码:

/**java * shop 客户管理 list * @param start * @param limit * @param selectValue */
    @ResponseBody
    @RequestMapping("/list_shop_customers_info")
    public Object listShopCustomerInfo(Integer start,Integer limit,String selectValue) {
        Page page = new Page();
        page.setStart(start);
        page.setLimit(limit);
        // 获取session中的用户信息
        User u = (User) this.request.getSession().getAttribute("userInfo");
        // 获取持久化用户对象
        User user = userService.findById(u.getUserId());
        if (user != null) {
            projectCustomerService.findShopCustomersByUser(user,selectValue,page);
            return page;
        }
    }

sevice层

@Override
    public void findShopCustomersByUser(User user,String selectValue,Page page) {
        List cmList = new ArrayList<>();
        int total = 0;
        if(user!=null && user.getParentId()!=null && !user.getParentId().equals("")){
            String hql = "from ShopCustomers as model where model.shopId = " + Integer.parseInt(user.getParentId());
            if(selectValue!=null && !selectValue.equals("")){
                hql+="and model.shopCustomerName like '%" +selectValue+"%' or model.shopCustomerPhone like '%" +selectValue+"%'";
            }
            List<ShopCustomers> list = baseDao.findByHql(hql,page.getStart(),page.getLimit());
            for(ShopCustomers sc : list){
                User u = (User) baseDao.loadById(User.class,sc.getUserId());
                String cGRSHql = "select count(*) from GuideRecords where shopCustomerId = '"+sc.getShopCustomerId()+"'";
                String cDealHql = "select count(*) from GuideRecords where shopCustomerId = '"+sc.getShopCustomerId()+"' and isDeal = 1";
                int floorCounts = baseDao.countQuery(cGRSHql);//备案楼盘数
                int dealCounts = baseDao.countQuery(cDealHql);//已成交数
                CustomerManager cm = new CustomerManager();
                CustomerManager cmObj = cm.createCusManObj(sc,u);
                cmObj.setRecords(floorCounts);
                cmObj.setAlreadyDeal(dealCounts);
                cmList.add(cmObj);
            }
            String cHql = "select count(*) "+hql;
            total = baseDao.countQuery(cHql);
        }
        page.setRoot(cmList);
        page.setTotal(total);
    }

分页对象

package com.sc.Tradmaster.utils;

import java.util.List;
/** * 分页对象 * @author grl 2017-01-05 * */
public class Page {
    /** 总记录数 */
    private int total;
    /** 分页结果 */
    private List root;
    /** 开始页码 */
    private int start;
    /** 每页多少 */
    private int limit;
    /** 查询条件 */
    private String wheres;

    private int currentPage;    //当前页
    private int currentResult;  //当前记录起始索引
    private int totalPage;      //总页数

    public int getCurrentPage() {
        if(currentPage<=0)
            currentPage = 1;
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getCurrentResult() {
        currentResult = (getCurrentPage()-1)*getLimit();
        if(currentResult<0)
            currentResult = 0;
        return currentResult;
    }

    public void setCurrentResult(int currentResult) {
        this.currentResult = currentResult;
    }

    public int getTotalPage() {
        if(total%limit==0)
            totalPage = total/limit;
        else
            totalPage = total/limit+1;
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List getRoot() {
        return root;
    }

    public void setRoot(List root) {
        this.root = root;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public String getWheres() {
        return wheres;
    }

    public void setWheres(String wheres) {
        this.wheres = wheres;
    }

    @Override
    public String toString() {
        return start+" "+total +" " +root;
    }

}

如果遇到问题请联系我

layui完美分页,ajax请求分页真分页 【2.0版本】的更多相关文章

  1. ios – UIScrollView的平滑自定义分页

    我在UIScrollView中有两个(可能更多)视图,并希望使用分页.当我尝试使用UIScrollView的默认分页选项时出现问题,因为视图具有不同的宽度,无法正确分页.所以我已经实现了一个有效的自定义分页代码.但是,当滚动较慢时,它不会按预期运行.(它回到没有动画的原始位置.)以下是我目前通过uiscrollviewdelegate进行自定义分页的方法我想要的是:是)我有的:解决方法尝试下面的自

  2. ios – 使用子视图控制器分页滚动视图

    使用分页实现水平滚动视图的最佳做法是什么,每页有一个视图控制器?由于iOS5具有用于视图控制器容器/包含的API,因此PageControl示例仍然是实现此功能的最佳方式吗?

  3. 可可触摸 – 启用预览和分页的UICollectionView

    在AppStore中显示搜索结果时,我正在尝试模仿苹果公司的功能.(参考:http://searchengineland.com/apple-app-search-shows-only-one-result-at-a-time-133818)它显示像卡中的详细应用程序信息,并且它被分页.当中间的一个活动卡片和滚动视图的分页行为仍然完整时,我被困在如何使上一张和第二张卡片显示.我已经尝试使用UICo

  4. ios – 启用了内容插入的UIScrollView分页工作很奇怪

    我创建了具有内容插入的UIScrollView.第一次,scrollView.contentOffset.x为-160.0但是奇怪的问题是当我点击scrollView(黄色区域)时,内容偏移x值将重置为0并显示为这样.我尝试过几次,但是点击滚动视图会将内容偏移量重置为0.我该如何防止这种情况?解决方法UIScrollView分页通过滚动与scrollView宽度相同的页面(在您的情况下为480个宽

  5. 应用程序关闭时的iOS任务

    我正在构建一个应用程序,通过ajax将文件上传到服务器.问题是用户很可能有时不会有互联网连接,并且客户希望在用户重新连接时安排ajax调用.这可能是用户在离线时安排文件上传并关闭应用程序.应用程序关闭时可以进行ajax调用吗?

  6. UIKit框架-高级控件Swift版本: 10.UIWebView方法/属性详解

    前面我们已经讲解完了UINavigationController的一些常用属性以及方法,现在让我们来看看一个关于网络的UIWebView.1.UIWebView的常用属性常用类型2.UIWebView的代理方法3.代码示范首先我们要使用storyBoard布局界面关联控件遵守代理协议自定义UIWebVIew实现代理方法在ViewDidLoad方法中实现PS:UIWebView继承与UIView,并

  7. swift+storyboard+UIImageview入门

    更新记录:该Storyboard教程由CarolineBegbie更新iOS8和Swift相关内容。Storyboard是最先在iOS5引入的一项振奋人心的特性,大幅缩减构建App用户界面所需的时间。要介绍Storyboard是什么,我打算从这张图讲起。这就是使用Storyboard的力量。Storyboard通过新的原型表项和静态表项特性,让处理表视图的工作更加轻松。Storyboard使自动布局更易用。接下来我们看一下Storyboard,点击项目浏览器中的Main.storyboard就可以在Int

  8. 使用RxSwift进行分页API调用

    如何实现这一点的任何建议将非常感谢…

  9. android – Phonegap本地构建 – jquery ajax错误:readystate 0 responsetext status 0 statustext error

    解决方法您是否在索引文件中包含了内容安全元标记?

  10. Ajax简单的异步交互及Ajax原生编写

    一提到异步交互大家就会说ajax,仿佛ajax这个技术已经成为了异步交互的代名词.那下面将研究ajax的核心对象

随机推荐

  1. xe-ajax-mock 前端虚拟服务

    最新版本见Github,点击查看历史版本基于XEAjax扩展的Mock虚拟服务插件;对于前后端分离的开发模式,ajax+mock使前端不再依赖后端接口开发效率更高。CDN使用script方式安装,XEAjaxMock会定义为全局变量生产环境请使用xe-ajax-mock.min.js,更小的压缩版本,可以带来更快的速度体验。

  2. vue 使用 xe-ajax

    安装完成后自动挂载在vue实例this.$ajaxCDN安装使用script方式安装,VXEAjax会定义为全局变量生产环境请使用vxe-ajax.min.js,更小的压缩版本,可以带来更快的速度体验。cdnjs获取最新版本点击浏览已发布的所有npm包源码unpkg获取最新版本点击浏览已发布的所有npm包源码AMD安装require.js安装示例ES6Module安装通过Vue.use()来全局安装示例./Home.vue

  3. AJAX POST数据中文乱码解决

    前端使用encodeURI进行编码后台java.net.URLDecoder进行解码编解码工具

  4. Koa2框架利用CORS完成跨域ajax请求

    实现跨域ajax请求的方式有很多,其中一个是利用CORS,而这个方法关键是在服务器端进行配置。本文仅对能够完成正常跨域ajax响应的,最基本的配置进行说明。这样OPTIONS请求就能够通过了。至此为止,相当于仅仅完成了预检,还没发送真正的请求呢。

  5. form提交时,ajax上传文件并更新到&lt;input&gt;中的value字段

  6. ajax的cache作用

    filePath="+escape;},error:{alert;}});解决方案:1.加cache:false2.url加随机数正常代码:网上高人解读:cache的作用就是第一次请求完毕之后,如果再次去请求,可以直接从缓存里面读取而不是再到服务器端读取。

  7. 浅谈ajax上传文件属性contentType = false

    默认值为contentType="application/x-www-form-urlencoded".在默认情况下,内容编码类型满足大多数情况。在这里,我们主要谈谈contentType=false.在使用ajax上传文件时:在其中先封装了一个formData对象,然后使用post方法将文件传给服务器。说到这,我们发现在JQueryajax()方法中我们使contentType=false,这不是冲突了吗?这就是因为当我们在form标签中设置了enctype=“multipart/form-data”,

  8. 909422229_ajaxFileUpload上传文件

    ajaxFileUpload.js很多同名的,因为做出来一个很容易。我上github搜AjaxFileUpload出来很多类似js。ajaxFileUpload是一个异步上传文件的jQuery插件传一个不知道什么版本的上来,以后不用到处找了。语法:$.ajaxFileUploadoptions参数说明:1、url上传处理程序地址。2,fileElementId需要上传的文件域的ID,即的ID。3,secureuri是否启用安全提交,默认为false。4,dataType服务器返回的数据类型。6,error

  9. AJAX-Cache:一款好用的Ajax缓存插件

    原文链接AJAX-Cache是什么Ajax是前端开发必不可少的数据获取手段,在频繁的异步请求业务中,我们往往需要利用“缓存”提升界面响应速度,减少网络资源占用。AJAX-Cache是一款jQuery缓存插件,可以为$.ajax()方法扩展缓存功能。

  10. jsf – Ajax update/render在已渲染属性的组件上不起作用

    我试图ajax更新一个有条件渲染的组件。我可以确保#{user}实际上是可用的。这是怎么引起的,我该如何解决呢?必须始终在ajax可以重新呈现之前呈现组件。Ajax正在使用JavaScriptdocument.getElementById()来查找需要更新的组件。但是如果JSF没有将组件放在第一位,那么JavaScript找不到要更新的内容。解决方案是简单地引用总是渲染的父组件。

返回
顶部