分页实现方法

方法一  前台页面的定义分页展示  easy ui

pagination : true,
        pageSize : 5,
        pageList : [ 5, 10, 15, 20, 50 ],

每次页面操作或者查询请求CURD时 响应头部都会带着页面page和rows属性。所以后台可以指定接收参数 进行分页。

例如 在初始化的时候。我们会创建一个page的 bean用来接收前台传入的page 和 row、

public class PageBean {

    private Integer page;
    private Integer rows;
    public Integer getPage() {
        return page;
    }
    public void setPage(Integer page) {
        this.page = page;
    }
    public Integer getRows() {
        return rows;
    }
    public void setRows(Integer rows) {
        this.rows = rows;
    }

}

再定义一个 pagination来方便json数组操作。

public class Pagination {

    private List<Object> rows;
    private String total;

    public List  getRows() {
        return rows;
    }
    public void setRows(List  rows) {
        this.rows = rows;
    }
    public String getTotal() {
        return total;
    }
    public void setTotal(String total) {
        this.total = total;
    }

}
Pagination p = new Pagination();
        p = dayRecruitService.find(page, ds,date_start,date_end,account);
        //注意序列化。这样可以直接引用,例如  row.customer.organization.organizationName
        String json = "{\"total\":" + p.getTotal() + " , \"rows\":"
            + JSON.toJSONString(p.getRows(),SerializerFeature.DisableCircularReferenceDetect) + "}";
        return json;

直接调用find方法从数据库取出数据就可以了。结果会转化成json数据集然后显示在前台页面的。

我自己写了一个简单的分页实现,比上边方法直接,直观。

    @RequestMapping("/find_test")
    private void find_test(HttpServletRequest request,
            HttpServletResponse response) {
        //将登陆写死在数据中
        Account account = this.getStaticAccount();
        try {
            //获得后台的 page  row http会包含在post头中
            int currentPage = Integer.parseInt(request.getParameter("page"));
            int pageSize    = Integer.parseInt(request.getParameter("rows"));
            //有查询条件的 序列成map来管理
            String date_start = request.getParameter("date_start")== null?"":request.getParameter("date_start");
            String date_end   = request.getParameter("date_end")== null?"":request.getParameter("date_end");
            String orgid     = request.getParameter("orgid")== null?"":request.getParameter("orgid");
            String customerid     = request.getParameter("customer.id")== null?"":request.getParameter("customer.id");
            Map<String, Object> searchmap = new HashMap<String, Object>();
            searchmap.put("date_start", date_start);
            searchmap.put("date_end", date_end);
            searchmap.put("orgid", orgid);
            searchmap.put("customer.id", customerid);
            //    分页显示
            List<DayRecruit> dayRecruits = this.dayRecruitService.findByPagination(currentPage , pageSize,searchmap,account);
            int total = this.dayRecruitService.getTotal();
            response.setContentType("text/html;charset=utf-8");
            //{"total":10 , "rows":[{},{}]}
            String json = "{\"total\":"+total+" , \"rows\":"+JSON.toJSONString(dayRecruits,SerializerFeature.DisableCircularReferenceDetect)+"}";
            response.getWriter().write(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

牵扯到的hql关键语句为

            Query query = session.createQuery(hql);
            query.setFirstResult((currentPage-1)*pageSize); //从第0条开始
            query.setMaxResults(pageSize); //取出10条
            List<DayRecruit> dayrecruit = query.list();
            return dayrecruit;
时间: 2024-08-28 15:59:56

分页实现方法的相关文章

MVCPager分页使用方法

public ActionResult AdminUserList(UserListModel model) { var pagedList = _userService.SearchAdminUsers(model.PageIndex, model.PageSize, model.Name, model.IsActive); model.Items = new PagedList<UserListItem>(Mapper.Map<List<UserListItem>>

Python中使用flask_sqlalchemy实现分页效果方法详解

Flask-sqlalchemy是关于flask一个针对数据库管理的.本文我们将采用一个关于员工显示例子,为大家展示分页效果的实现,一起来看看吧,希望对大家学习python有所帮助. 首先,我们创建SQLALCHEMY对像db. 1 from flask import Flask, render_template,request 2 from flask_sqlalchemy import SQLAlchemy 5 6 app = Flask(__name__,static_url_path='

AspNetPager控件分页使用方法

AspNetPager控件官方下载地址:http://www.webdiyer.com/aspnetpager/ 把控件加到项目中(添加自定义控件的方法),并把它拖放到页面上 <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="

各种数据库分页查询方法

具体实现中,根据所用数据库.数据量.实现分页方式,选择分页实现快的方式实现. 一.MYSQL分页查询方法 MYSQL分页查询主要使用其自带的limit函数,但需根据查询量来决定具体的使用方式,如只有几千或几万数据,则直接用 limit m,n方式, 如数据量较多,则要注意limit的使用方式. // limit m , n:从第 m 条数据开始,获取 n 条数据 1.数据量少的方式:select * from tablename limit m,n; // limit m , n:m 可省略,省

jQuery EasyUI datagrid实现本地分页的方法

本文实例讲述了jQuery EasyUI datagrid实现本地分页的方法.分享给大家供大家参考.具体如下: 一般分页都是后台做,前端做无论从哪方面考虑都不合适.但是有的时候还是有这种需求. 这里重点用到了pagination的监听,以及JS数组的slice方法来完成.代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 3

mysql limit分页优化方法分享

MySQL的优化是非常重要的.其他最常用也最需要优化的就是limit.MySQL的limit给分页带来了极大的方便,但数据量一大的时候,limit的性能就急剧下降. 同样是取10条数据 select * from yanxue8_visit limit 10000,10 和 select * from yanxue8_visit limit 0,10 就不是一个数量级别的. 网上也很多关于limit的五条优化准则,都是翻译自MySQL手册,虽然正确但不实用.今天发现一篇文章写了些关于limit优

Latex 算法过长 分页显示方法

参考: Algorithm tag and page break Latex 算法过长 分页显示方法 1.引用algorithm包: 2.在\begin{document}前加上以下Latex代码: \makeatletter \newenvironment{breakablealgorithm} {% \begin{breakablealgorithm} \begin{center} \refstepcounter{algorithm}% New algorithm \hrule height

limit 百万级数据分页优化方法

mysql教程 这个数据库教程绝对是适合dba级的高手去玩的,一般做一点1万 篇新闻的小型系统怎么写都可以,用xx框架可以实现快速开发.可是数据量到了10万,百万至千万,他的性能还能那么高吗? 一点小小的失误,可能造成整个系统的改写,甚至更本系统无法正常运行!好了,不那么多废话了. 用事实说话,看例子:数据表 collect ( id, title ,info ,vtype) 就这4个字段,其中 title 用定长,info 用text, id 是逐渐,vtype是tinyint,vtype是索

c# 分页的方法

返回的是list集合: /// <summary> /// 返回合同的款项信息 /// </summary> /// <param name="pagesize"></param> /// <param name="currentpage"></param> /// <param name="totalcount"></param> /// <r