| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 912 人关注过本帖
标题:ssh1分页(hibernate分页)
只看楼主 加入收藏
a123213813
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2010-12-9
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
ssh1分页(hibernate分页)
最近做个web项目,遇到点难题,网上贴子贴的代码都不全,希望大侠能指点指点。 最好给个全面的分页实例。 hibernate用的Query的接口查询。

W.s-yangtao@
搜索更多相关主题的帖子: ssh hibernate 
2010-12-22 11:47
cdxkyz928
Rank: 2
等 级:论坛游民
帖 子:7
专家分:19
注 册:2008-10-19
收藏
得分:7 
看不懂啊 哎 什么时候才能看懂啊~!

传奇百区外挂 www.mir2fz.co m
2010-12-22 17:14
mary_xiaoman
Rank: 2
来 自:湖南岳陽
等 级:论坛游民
威 望:3
帖 子:13
专家分:55
注 册:2010-12-21
收藏
得分:7 
给你一个分页类,直接在action里调用就可以了,代码给你贴出来!
----------------------------------------------------------------------------------
分页类:
public class MyPageList {

    private PagedListHolder pagedlist;

    public static final int PAGESIZE = 15; // 每页显示几条记录

    public MyPageList(List list) {
        this.pagedlist = new PagedListHolder(list);
    }

    public List getInstance() {
        pagedlist.setPageSize(PAGESIZE);
        return pagedlist.getPageList();
    }

    public List getInstance(int PAGESIZE) {
        pagedlist.setPageSize(PAGESIZE);
        return pagedlist.getPageList();
    }

    public List next() {//下一页
        pagedlist.nextPage();
        return pagedlist.getPageList();
    }

    public List prep() {//上一页
        pagedlist.previousPage();
        return pagedlist.getPageList();
    }
   
    public List first() {//首页
        for (int i = 0; i < pageCount(); i++) {
            if (pagedlist.isFirstPage()) {
                break;
            }
            pagedlist.previousPage();
        }
        return pagedlist.getPageList();
    }

    public List last() {//最后一页
        for (int i = 0; i < pageCount(); i++) {
            if (pagedlist.isLastPage()) {
                break;
            }
            pagedlist.nextPage();
        }
        return pagedlist.getPageList();
    }

    public int pageCount() {//总共多少页
        return pagedlist.getPageCount();
    }

    public int pageNumber() {//第几页
        return pagedlist.getPage() + 1;
    }

}
----------------------------------------------------------------------------------
action中的代码:

    MyPageList myPageList = null;

    public ActionForward doPage(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
    {
        String op=request.getParameter("op");
        
        List list=new ArrayList();
        if(op != null)
        {
            if(op.equals("prep"))
            {
                list=myPageList.prep();
            }
            else if(op.equals("next"))
            {
                list=myPageList.next();
            }
            else if(op.equals("first"))
            {
                list=myPageList.first();
            }
            else if(op.equals("last"))
            {
                list=myPageList.last();
            }
        }

        request.getSession().setAttribute("warnList", list);
        request.getSession().setAttribute("pageNumber", myPageList.pageNumber());
        
        return mapping.findForward("warnInfo");
    }

----------------------------------------------------------------------------------
                                            页面中的代码:

                                                        <td>
                                                            <a href="warn.do?method=doPage&op=first"> 第一页 </a>
                                                        </td>
                                                        <td>
                                                            <a href="warn.do?method=doPage&op=prep"> 上一页 </a>
                                                        </td>
                                                        <td>
                                                            <a href="warn.do?method=doPage&op=next">下一页 </a>
                                                        </td>
                                                        <td>
                                                            <a
                                                                href="warn.do?method=doPage&op=last"> 最后页 </a>
                                                        </td>
2010-12-23 10:04
努力加油
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:34
专家分:127
注 册:2010-4-11
收藏
得分:7 
  精彩
2010-12-27 08:33
快速回复:ssh1分页(hibernate分页)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020279 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved